如何在UINavigationController中添加向右按钮?

想要在navigation controller 的顶端条添加一个刷新键。不知道为什么不执行。
hearder代码:
@interface PropertyViewController : UINavigationController {}
添加button代码:

  • (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; } 不知道错误在哪儿

你可以断点看看,这段代码有没有执行。初始化方法有多个,检查一下调用的对不对?

https://www.jianshu.com/p/104c31b8cfc2

将initWithNibName:bundle:替换为initWithRootViewController: