gpt4 book ai didi

iphone - 如何向 UINavigationController 添加右键?

转载 作者:IT王子 更新时间:2023-10-29 07:26:10 25 4
gpt4 key购买 nike

我试图将刷新按钮添加到导航 Controller 的顶部栏,但没有成功。

这是标题:

@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];
}

至于为什么它目前不工作,我不能在没有看到更多代码的情况下 100% 肯定地说,但是在初始化和 View 加载之间发生了很多事情,你可能正在做一些导致 navigationItem 的事情在两者之间重置。

关于iphone - 如何向 UINavigationController 添加右键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1219779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com