Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd image to subclassed UIImageView
    primarykey
    data
    text
    <p>I am trying to add a tap gesture from a subclassed UIImageView and then control the tap from the View Controller. I am not getting any compiling errors but "addSubview" is not displaying any image. How can make the UIImageView to be displayed?</p> <p>If I try to control the tap and pan gestures from the subclassed UIImageVIew I have no problems but I would like to control these functions from the View Controller</p> <p>Relevant code looks like this.</p> <p>UIImageView subclass    </p> <pre><code>- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { //self.userInteractionEnabled = YES; previewController = [[PreviewController alloc]init]; [previewController self]; [self addSubview:character]; // Tap Initialization code UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:(PreviewController *)self.previewController action:@selector(addCharacter:)]; [self addGestureRecognizer:tap]; self.userInteractionEnabled = YES; } return self; } </code></pre> <p>View Controller</p> <pre><code>- (void)addCharacter:(UITapGestureRecognizer *)t { NSLog(@"add character"); imageNSArray = [NSMutableArray array]; uiImg = [UIImage imageNamed:@"homer.png"]; CGPoint loc = [t locationInView:self.view]; character = [[UIImageView alloc] initWithImage:uiImg]; character.center = loc; [imageNSArray addObject:character]; //Locate the imageNSArray on frameImageView area only. [self.view addSubview:character]; UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panCharacter:)]; [self.character addGestureRecognizer:pan]; character.userInteractionEnabled = YES; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload