【问题标题】:Why won't self.navigationController pushViewController work?为什么 self.navigationController pushViewController 不起作用?
【发布时间】:2010-11-19 04:03:47
【问题描述】:

我有一个

UIViewController-> UINavigationBar + UITableView

稍微解释一下

我通过 UIBuilder..

1: 使用 XIB 文件创建了一个新的 UIViewController
2: 使用 UIBuiler 我放了一个 UINavigationController
3: 然后我把UITableView 放在navigationBar 下面 所以它给了我..

A:UIViewController-> UINavigationBar + UITableView

现在我正在从运行良好的 Web 服务加载 UITableView 中的数据。

我再次用 sam config 制作了一个 xib,它是

B: UIViewController-> UINavigationBar + UITableView

所以现在当我尝试使用下面的代码将视图 B 推送到视图 A 时...它根本不起作用...

SelectSiteViewController *siteViewController = [[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" bundle:nil];

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

当我检查了UINavigationController *nav = self.navigation

nav 是 0x0,我假设 NIL。

谁能告诉我这里出了什么问题..为什么它是零......我怎样才能让它工作..

非常感谢....我非常感谢您的帮助

【问题讨论】:

    标签: ios objective-c uinavigationcontroller


    【解决方案1】:

    在 UIBuilder 中验证 UINavigationController 是否被文件的所有者引用。

    【讨论】:

    • 当您从 UIBuilder 库中删除 UINavigationBar 时,它是 UINavigationController 吗?它是一个 UINavigationBar。
    • 它只是出现在视图中的栏。您需要在 UIBuilder 中拖放 UINavigationController 并将其连接到文件所有者的导航控制器。或者您可以在代码中创建。
    • 嘿,我可以把代码发给你吗....我试过但不知道...我真的很感激任何帮助...谢谢男人
    • 我强烈建议您阅读“Head First Iphone Development”。它写得非常好,并且有你正在尝试做的事情的例子。它将为您节省无数时间并帮助您快速提高工作效率。
    【解决方案2】:

    知道了。

    我稍微改变了架构。

    我用它的 xib 创建了一个新的 UIViewController 类。并编写了新的 UINavigationController。

    - (void)viewDidLoad {
    [super viewDidLoad];
        UINavigationController *navigationController
    navigationController = [[UINavigationController alloc] init];
    [self.view addSubview:navigationController.view];   
    
    
    switch (whichViewController) {
        case 1:
            viewController = [[xxxx alloc] init];           
            break;
        case 2:
            viewController = [[xxx1 alloc] init];           
            break;
        default:
            break;
    }
    
    [navigationController pushViewController:viewController animated:NO];
    [viewController release];
    

    }

    并在 Switch 语句中推送视图....

    我希望这是有道理的......

    谢谢jamihash

    【讨论】:

      【解决方案3】:

      所以您将 tableview 添加到导航控制器对吗?方法如下:

      tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
      
      navigationController = [[UINavigationController alloc] init];
      
      [navigationController pushViewController:tableView animated:NO];
      

      表格视图作为根视图添加到导航控制器。然后在选择一行时,如果您希望推送另一个视图控制器,请使用

      self.navigationController pushViewController: newViewController animated:YES]; 
      

      在 didSelectRowAtIndex 方法中。

      注意:它的 UITableViewController *tableView 和 UINavigationController *navigationController 通过声明。因此,为您的表格进行相应的编码。

      【讨论】:

      • 不不...我创建了一个新文件,它是 UIViewController 并选择了 XIB 选项。例如:@interface ClasssName : UIViewController { } 所以它是 UIViewController 的子类现在我打开 xib 文件并拖放 UINavigationBar 然后我将 UITableView 拖放到作为 UIViewController 的 xib 文件上这有帮助吗?
      【解决方案4】:

      为什么是 UIViewController-> UINavigationBar + UITableView ?

      我建议你另一种方法 ->UITableViewController A -> 嵌入导航控制器,然后在填充表格视图后,您可以将数据传递给 ->UITableViewController B 通过 [[self storyboard]instantiateViewControllerWithIdentifier:@"ControllerB"];

      然后,在 storyboard 中,放置一个 tableView B 并在 Identity->storyboard Id 中放置一些 id。

      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   *)indexPath
      {
      NSString *sUrl= @"<#string#>";
      if (indexPath.row == 0) sUrl= @"http://www.apple.com/";
      if (indexPath.row == 1) sUrl= @"http://www.google.com/";
      if (indexPath.row == 2) sUrl= @"http://www.times.uk/";
      
      NSMutableArray *selectedObject = [arrayOpenMale objectAtIndex:0];
      NSLog(@"%@ is the selected object.",selectedObject);
      
      SeriesAdetailVC *dvc = [[self  storyboard]instantiateViewControllerWithIdentifier:@"DetailView"];
      dvc.strings7 = [NSURL URLWithString:sUrl];
      
      [self.navigationController pushViewController:dvc animated:YES];
      
      }
      

      希望帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-23
        • 1970-01-01
        • 2013-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多