Pathetic Learner
Pathetic Learner

Reputation: 729

Action on image in iphone

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

Upvotes: 3

Views: 3421

Answers (3)

Yama
Yama

Reputation: 2649

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?

Upvotes: 7

Ravi
Ravi

Reputation: 8309

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...)

Upvotes: 1

Yannick
Yannick

Reputation: 1106

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'

Upvotes: 3

Related Questions