为什么self.navigationController pushViewController不工作?
我有一个
UIViewController-> UINavigationBar + UITableView
多一点解释
我通过UIBuilder制作
1:用XIB文件创build一个新的UIViewController
2:使用UIBuiler
我把一个UINavigationController
3:然后我把UITableView
下的navigationBar
UITableView
,所以它给了我..
答:UIViewController-> UINavigationBar + UITableView
现在我正在从正在工作的Web服务加载UITableView中的数据。
我又用samconfiguration了一个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
导航是0x0,我假设为零。
有人可以告诉我这里有什么错误吗?为什么它是零…我怎样才能使它工作..
非常感谢….我真的很感激任何帮助
在UIBuilder中,validationUINavigationController是由文件所有者引用的。
得到它了。
我改变了build筑一点点。
我用它的xib创build了一个新的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];
}
并在交换声明中推送视图….
我希望这是有道理的 ……
谢谢jamihash
所以你要添加tableview到导航控制器的权利? 这是如何:
tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; navigationController = [[UINavigationController alloc] init]; [navigationController pushViewController:tableView animated:NO];
tableview被作为rootview添加到导航控制器。 然后在select一个行,如果你想推另一个viewcontroller使用
self.navigationController pushViewController: newViewController animated:YES];
在didSelectRowAtIndex方法中。
注意:它的UITableViewController * tableView和UINavigationController *的navigationController声明。 所以相应地为你的表编码。
为什么UIViewController-> UINavigationBar + UITableView?
我build议你另一种方法 – > UITableViewController A – >与导航控制器embedded,然后填充tableview后,您可以通过[[self storyboard] instantiateViewControllerWithIdentifier:@“ControllerB”]传递数据到 – > UITableViewController B;
然后,在故事板中,放置一个tableView B,并在身份 – >故事板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]; }
希望有所帮助