gpt4 book ai didi

iphone - 尝试以编程方式创建 rightBarButtonItem

转载 作者:行者123 更新时间:2023-12-03 18:23:54 24 4
gpt4 key购买 nike

这似乎不起作用。我究竟做错了什么?

-(void)awakeFromNib{
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showNewEventViewController)];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
NSLog(@"awaked");
[rightBarButtonItem release];
}

最佳答案

我的猜测是,您将 UIBarButtonItem 添加到了错误的对象!您需要将其添加到 rootViewController(而不是像您可能所做的那样添加到 UINavigationController)

YourRootViewController *theRootController = [[YourRootViewController alloc] init];

UINavigationController* navContainer = [[UINavigationController alloc] initWithRootViewController:theRootController];

UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(dismiss)];
theRootController.navigationItem.rightBarButtonItem = btnCancel

[navContainer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:navContainer animated:YES];

关于iphone - 尝试以编程方式创建 rightBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2090365/

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