0

我的导航栏有问题。问题是我试图覆盖 NavigationBar 从超级 viewController 拥有的 LeftBarButtonItem,如下所示:

“超级视图控制器”

UIImageView *logoApp = [[UIImageView alloc] initWithImage:[UIImageimageNamed:@"logo.png"]];
[logoApp setFrame:CGRectMake(5, 5, 55, 30)];
UIBarButtonItem *containingLogoApp = [[UIBarButtonItem alloc] initWithCustomView:logoApp];
self.navigationItem.leftBarButtonItem = containingLogoApp;

现在我试图在不同的 viewControllerB 中覆盖它,如下所示:

UIImageView *backImg = [[UIImageView alloc] initWithImage:[UIImageimageNamed:@"back.png"]]; 
[logoApp setFrame:CGRectMake(5, 5, 17, 22)];
UIBarButtonItem *containingBackButton = [[UIBarButtonItem alloc]initWithCustomView:backImg]; 
self.navigationItem.leftBarButtonItem = containingBackButton;

这是相同的代码,并且仅在应用程序第一次运行时才有效。如果我第二次运行它,它不再显示分配的图像ViewControllerB。这发生在我项目中的每个图像上,它仅在我第一次在模拟器上运行应用程序时才有效,在第一次运行之后......就像什么都没发生一样。

如何覆盖 leftBarButtonItem?

4

2 回答 2

0

试试这个代码

UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"dynamic_blue_left.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(rightSwipeClicked:)];
self.navigationItem.leftBarButtonItem = backButton;

它工作正常..可能对你有用

于 2013-09-16T13:58:43.887 回答
0
UIButton *backButton =  [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
[backButton setFrame:CGRectMake(0, 0, 50, 30)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
于 2013-09-13T11:49:57.437 回答