我试图将刷新按钮添加到导航控制器的顶部栏,但没有成功。
这是标题:
@interface PropertyViewController : UINavigationController {
}
这是我尝试添加它的方法:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Show" style:UIBarButtonItemStylePlain
target:self action:@selector(refreshPropertyList:)];
self.navigationItem.rightBarButtonItem = anotherButton;
}
return self;
}
尝试在 viewDidLoad 中执行此操作。一般来说,无论如何,您都应该将所有可以推迟的事情推迟到那时,当 UIViewController 初始化时,它可能仍然需要相当长的一段时间才能显示,尽早完成工作并占用内存是没有意义的。
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Show" style:UIBarButtonItemStylePlain target:self action:@selector(refreshPropertyList:)];
self.navigationItem.rightBarButtonItem = anotherButton;
// exclude the following in ARC projects...
[anotherButton release];
}
至于为什么它目前不起作用,我不能在没有看到更多代码的情况下百分百肯定地说,但是在 init 和视图加载之间发生了很多事情,并且您可能正在做一些导致 navigationItem 在中重置的事情之间。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)