views:

65

answers:

3

Hi Buddies,

I want to display the image in navigation bar instead of back button with action. So now i have used image view and displayed the image in the navigation bar. Now i want to write the actions for image view, when touch or click the image view. Is it possible to write a actions for image view?.

I am currently working in iPhone OS 4.0.

please see My previous quetion

Here my code is,

     UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0,5,40,40)];
     [self.navigationController.navigationBar addSubview:view1];
     view1.backgroundColor = [UIColor clearColor];

     UIImage *img = [UIImage imageNamed:@"Back.png"];
     UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
     [view1 addSubview:imgView];

How can i write the actions for image view.

So please help me out.

Thanks.

+1  A: 

Before iOS 3.2, nou would need a sublass of UIImageView and implement the touch handlers. Or replace your UIImageView with a UIButton with custom type.

With iOS 3.2+, UIGestureRecognizer is what gets your things done efficiently - just add the appropriate one to your view.

Eiko
A: 

Don't add views directly to the navigation bar unless you're prepared for it to break in a future OS release.

UIButton * b = [UIButton buttonWithType:UIButtonTypeCustom];
b.image = [UIImage imageNamed:@"Back.png"];
b.frame = (CGRect){{0,0},{40,40}};
[b addTarget:self action:@selection(wahatever) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:b] autorelease];
tc.
+1  A: 

Hi

See my answer

Refer it and it will help you.

Sivanathan