当我根据存储的状态自动跳转到该视图时,为什么工具栏项目没有出现?

发布于 2024-11-01 22:04:05 字数 1837 浏览 7 评论 0原文

我试图理解为什么当我在启动并查看存储状态后自动跳转到第二个视图(使用 UINavigationController)时,工具栏项目没有出现?

当我返回主页(通过 UINavigationController 标准安排),然后选择 UITableView 中的行,并再次返回同一视图时,工具栏项目显示正常。

代码摘录给出的粗略想法是:

ma​​inController - 基于正常选择的条目

  • 通过“didSelectRowAtIndexPath”
  • 创建新的视图控制器并将 (pushViewController) 推入堆栈

ma​​inController - 重新启动时&检查先前状态用户是否处于第二层视图

  • 在 vi​​ewDidLoad 方法的底部检查先前视图的状态
  • 如果需要,则按照与上面正常选择方法相同的方法自动跳转到第二层视图 - 事实上我重构了代码,以便在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失眠症患者 2024-11-08 22:04:05

我发现 Objective-C 的一个特性非常烦人且容易出错,那就是在空对象上调用方法时会出现静默失败。在 setupToolBar 方法中的第一行之后,检查 navigationController 是否为 null:

  NSLog(@" navigationController is 0x%x", self.navigationController);

对于重新启动情况,导航控制器是否以与常规情况相同的方式创建?

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:

  NSLog(@" navigationController is 0x%x", self.navigationController);

Is the navController created in the same manner for the restart case as in the regular case?

莫言歌 2024-11-08 22:04:05

我想出了如何通过消除过程来解决这个问题,但我不明白为什么:)

那么解决这个问题的方法是更改​​应用程序委托的“didFinishLaunchingWithOptions”方法中的以下行:

  // OLD Entry - Did not work
  //[self.window addSubview:navigationController.view];

  // NEW Entry - Fixed it
  self.window.rootViewController = self.navigationController;

有什么想法吗?

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:

  // OLD Entry - Did not work
  //[self.window addSubview:navigationController.view];

  // NEW Entry - Fixed it
  self.window.rootViewController = self.navigationController;

Any ideas why?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文