【问题标题】:pushViewController doing nothing in multiple tab app?pushViewController 在多个标签应用程序中什么都不做?
【发布时间】:2010-10-04 14:36:01
【问题描述】:

我有一个基于窗口的 iPhone 应用程序,其中包含多个选项卡和一个显示在所有这些选项卡上的导航栏控制器。这是一个天气/气候应用程序,所以我希望用户首先选择一个城市,然后在该城市的每个选项卡中显示天气信息(他们可以使用导航栏从任何选项卡返回城市选择。我跟着这个指南:http://www.youtube.com/watch?v=LBnPfAtswgw 但添加了更多具有相同设置的选项卡。 所以我得到当前选项卡并像这样实例化应用程序委托:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSUInteger currTab;
AppDelegate_iPhone *delegate = [[UIApplication sharedApplication] delegate];
currTab = delegate.rootTabController.selectedIndex;
...

这很好,在 viewDidAppear 中调用时返回正确的选定选项卡。然后我的代码推送到相应的视图(在本例中为 UIForecastViewController),如下所示:

if (currTab == 0) {
    if (self.forecastViewController == nil) {
        UIForecastViewController *chosenCity = [[UIForecastViewController alloc] initWithNibName:@"UIForecastViewController" bundle:nil];
                   // note forecastViewController is a variable, not the class
        self.forecastViewController = chosenCity;
        [chosenCity release];
    }
    forecastViewController.title = [NSString stringWithFormat:@"%@ Forecast",[cityArray objectAtIndex:row]];
    [delegate.navController pushViewController:forecastViewController animated:YES];
}

其他一切都正常工作,但 pushViewController 什么也不做。我已经毫无结果地寻找解决方案,那里有一些类似的例子,但没有使用应用程序委托或给我任何结果。希望我已经提到了我应该拥有的一切,任何帮助/建议将不胜感激!问候。

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitabbarcontroller pushviewcontroller


    【解决方案1】:

    delegatenavController 属性为零。我将首先查看应该设置它的代码。

    你有什么理由不使用这个?

    [self.navigationController pushViewController:forecastViewController animated:YES];
    

    【讨论】:

    • 显然是因为我很傻。这对每个标签都非常有效,您先生是一位绅士和一位学者。 (澄清一下,我使用的是委托,因为教程就是这样做的,它适用于单个选项卡,但显然在多个选项卡上中断。)非常感谢!
    猜你喜欢
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 2012-04-21
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多