tags:

views:

556

answers:

1

I have created a Tab Bar controller which has Navigation Bar and a Table View. I set an image on the left side as Subview of navigation bar as below.

CGRect frame = CGRectMake(5.0, 5.0, 94.0, 33.0);
image = [ [UIImageView alloc]initWithImage:[UIImage imageNamed:@"topBarImage.png"] ];
image.frame = frame;
[navBar addSubview:image];

It works as expected to show. For certain reasons, in the second page of of Tab Bar, i don't want to show the image in Navigation bar, so i have to remove it only for the second page. I tried removing it from removeFromSuperview, but not working as expected. Can anyone tell me how to iterate all the subviews from navigation bar and remove the particular image view?

A: 

please see my previous answer to the way you implemented this code incorrectly. What you have works, but it is the wrong way to do it and is the reason you are seeing this problem. While you are there, you could also mark my answers as "the answer" in stack overflow.

http://stackoverflow.com/questions/1422797/iphone-sdk-adding-image-on-navigation-bar/1422870#1422870

edit: answering the question, the image, when implemented as a barbuttonitem, will flow off the screen when you push/pull the next view controller as expected. This is the standard way of doing this

coneybeare
I don't want an image on top of button, i'm not going to do anything with this image. It should show just an image on navigation bar. That's all.
Clave Martin
please reread the code and the comment. This is THE way to do it. just because is is a button, doesnt mean you cant make it into your image that you want. Just because it is a button, it doesnt have to call any action.This is the easy and Apple supported way to do what you wish. If you fight it by trying different things, you are only going to make your life difficult.
coneybeare
Sorry Mr.Coney, YOU ARE PERFECT. Great help. thanks.
Clave Martin