当我根据存储的状态自动跳转到该视图时,为什么工具栏项目没有出现?
我试图理解为什么当我在启动并查看存储状态后自动跳转到第二个视图(使用 UINavigationController)时,工具栏项目没有出现?
当我返回主页(通过 UINavigationController 标准安排),然后选择 UITableView 中的行,并再次返回同一视图时,工具栏项目显示正常。
代码摘录给出的粗略想法是:
mainController - 基于正常选择的条目
- 通过“didSelectRowAtIndexPath”
- 创建新的视图控制器并将 (pushViewController) 推入堆栈
mainController - 重新启动时&检查先前状态用户是否处于第二层视图
- 在 viewDidLoad 方法的底部检查先前视图的状态
- 如果需要,则按照与上面正常选择方法相同的方法自动跳转到第二层视图 - 事实上我重构了代码,以便在 ViewDidLoad 设置工具栏内为这个
第二层视图
- 使用相同的方法/代码- 此方法中的
代码 代码:
- (void)setupToolbar {
[self.navigationController setToolbarHidden:NO];
UIBarButtonItem *increaseFontButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"icon_zoom_in.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(pressButtonIncreaseFont:)
];
UIBarButtonItem *decreaseFontButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"icon_zoom_out.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(pressButtonDecreaseFont:)
];
NSArray *items = [NSArray arrayWithObjects: increaseFontButton, decreaseFontButton, nil];
self.toolbarItems = items;
//release buttons
[increaseFontButton release];
[decreaseFontButton release];
}
有什么想法吗?查找故障的想法?
I'm trying to understand why when I automatically jump to a 2nd view (using UINavigationController) after startup and reviewing stored state, that the toolbar items do not appear?
When I go back to main page (via UINavigationController standard arrangements), and then then select the row in the UITableView, and go back into the same view again the toolbar items appear fine.
Code extracts to give the rough idea is:
mainController - normal selection based entry
- via "didSelectRowAtIndexPath"
- create new view controller and pushing (pushViewController) onto stack
mainController - upon restart & checking if previous state user was in 2nd layer view
- In bottom of viewDidLoad method check the state for previous view
- If need to then automatically jump to 2nd layer view by following same method as per the normal selection approach above - in fact I refactored the code for both to use the same method/code for this
2nd Layer View
- within ViewDidLoad setup the toolbar - code for this in this method
Code:
- (void)setupToolbar {
[self.navigationController setToolbarHidden:NO];
UIBarButtonItem *increaseFontButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"icon_zoom_in.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(pressButtonIncreaseFont:)
];
UIBarButtonItem *decreaseFontButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"icon_zoom_out.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(pressButtonDecreaseFont:)
];
NSArray *items = [NSArray arrayWithObjects: increaseFontButton, decreaseFontButton, nil];
self.toolbarItems = items;
//release buttons
[increaseFontButton release];
[decreaseFontButton release];
}
Any ideas? Ideas for fault finding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现 Objective-C 的一个特性非常烦人且容易出错,那就是在空对象上调用方法时会出现静默失败。在 setupToolBar 方法中的第一行之后,检查 navigationController 是否为 null:
对于重新启动情况,导航控制器是否以与常规情况相同的方式创建?
One feature of Objective-C I find highly annoying and error-prone is the silent failure of calling a method on a null object. After your first line in the setupToolBar method, check if the navigationController is null:
Is the navController created in the same manner for the restart case as in the regular case?
我想出了如何通过消除过程来解决这个问题,但我不明白为什么:)
那么解决这个问题的方法是更改应用程序委托的“didFinishLaunchingWithOptions”方法中的以下行:
有什么想法吗?
I worked out how to fix this through process of elimination, but I don't understand why :)
So what fixed it was changing the following line in the application delegate's "didFinishLaunchingWithOptions" method:
Any ideas why?