3

I am creating a program in which i am adding an image view on the view and i want after clicking on the image only, another detail view should appear.

NSString *imageName = [NSString stringWithFormat:[dic objectForKey:@"img"]]; 
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubView:imageView];

The detail view should appear with the navigation controller. Please help me to solve this problem

Pathetic Learner
  • 729
  • 1
  • 11
  • 21

3 Answers3

7

Do one thing, add a UIButton and set it as custom and add set the image as background of the UIButton and then you will be able to click on the same and navigate to other view. Hows that?

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
Yama
  • 2,649
  • 3
  • 31
  • 63
3

You can subclass UIImageView and overwrite the touchesEnded method. This way you can call your UINavigationController and push any other controller when someone touches your UIImageView.

@interface YourImageView : UIImageView
{

}

in your implementation file you type :

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // push view controller here or use a delegate 
    // and push the view controller somewhere else
}

Make sure you also set the userInteractionEnabled property of your UIImageView to 'YES'

Yannick
  • 1,076
  • 1
  • 11
  • 23
1

I once had a similar problem and here's the link to the solution: UIButton inside UIImageView does not respond to taps

(It's an extension to one of the answers given above...)

Community
  • 1
  • 1
Ravi
  • 7,929
  • 6
  • 38
  • 48