UIToolbar 项目未显示
我有一个 UINavigationController,它被推送到 DetailsViewController。在这个DetailsViewController中,我想使用每个UINavigationController(至少从iPhone OS3.0开始)附带的工具栏。
因此,在 DetailsViewController 的 viewDidLoad 中,我创建了一个 UIBarButtonItem,将其添加到数组中并将其传递给导航控制器:
- (void) viewDidLoad {
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(selectTemplate)];
NSArray *items = [NSArray arrayWithObject: item];
TestUIAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UINavigationController *navController = delegate.navigationController;
[navController setToolbarItems: items animated:NO];
[navController setToolbarHidden: NO animated: YES];
}
但是,由于某种原因,当 UIToolbar 在屏幕上动画显示时,该项目不会添加到工具栏。
是否必须使用 UIToolbar 完成某种特定的顺序才能使其工作?
PS:应用程序处于(强制)横向模式,并且 navigationController.view 具有旋转变换。这可能有什么关系吗?
I have a UINavigationController that gets pushed a DetailsViewController. In this DetailsViewController, I want to use the toolbar that comes with every UINavigationController (atleast, since iPhone OS3.0).
So, in viewDidLoad in my DetailsViewController I create a UIBarButtonItem, I add it to an array and hand it off to the navigation controller:
- (void) viewDidLoad {
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(selectTemplate)];
NSArray *items = [NSArray arrayWithObject: item];
TestUIAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UINavigationController *navController = delegate.navigationController;
[navController setToolbarItems: items animated:NO];
[navController setToolbarHidden: NO animated: YES];
}
But, for some reason, while the UIToolbar is animated on to screen, the item is not added to the toolbar.
Is there some sort of specific order things have to be done with the UIToolbar for this to work?
P.S.: the application is in (forced) landscape mode and the navigationController.view has a rotation transform on it. Could that have anything to do with it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
做了更多的挖掘和调试,我得出的结论是我尝试修改
navigationController
的方法是错误的。相反,我应该简单地设置DetailsViewController 的toolbarItems 属性。之后,我的代码运行良好:
Have done some more digging and debugging and I've come to the conclusion that my approach of trying to modify the
navigationController
was wrong. Instead I should've simply set the toolbarItems property of the DetailsViewController.After that, my code worked fine: