如何重新加载/重新分配导航栏项目?我使用一些更改导航栏的库,有时我有一个包,其中所有导航项都消失了。我在 viewWillAppear
中重新分配了正确的项目,例如:
UIButton *actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
actionButton.frame = CGRectMake(270, 0, 50, 50);
actionButton.adjustsImageWhenHighlighted = YES;
[actionButton setImage:[UIImage imageNamed:@"share.png"] forState:UIControlStateNormal];
[actionButton setImage:[UIImage imageNamed:@"share-active.png"] forState:UIControlStateHighlighted];
[actionButton addTarget:self action:@selector(presentActivity) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *actionBarButton = [[UIBarButtonItem alloc]initWithCustomView:actionButton];
actionBarButton.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = actionBarButton;
但它不起作用,有时我没有任何导航项。
最佳答案
UIBarButtonItem
不是 UIButton 的子元素。
这里没有像 setImage:forState:
等已知方法
像这样创建和定制一个 UITabBarButton
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(goBack)];
newBackButton.image = [UIImage imageNamed:@"back"];
self.navigationItem.leftBarButtonItem=newBackButton;
还要验证在 viewDidLoad
时是否会调用此代码的方法
关于ios - 重新加载导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23877079/