我的导航栏有问题。问题是我试图覆盖 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?