[英]Why won't self.navigationController pushViewController work?
I have a 我有一个
UIViewController-> UINavigationBar + UITableView
UIViewController-> UINavigationBar + UITableView
Just a bit more explanation 只是更多的解释
I made it through UIBuilder.. 我是通过UIBuilder实现的。
1: Created a New UIViewController
with XIB-file 1:使用XIB文件创建一个新的
UIViewController
2: Using UIBuiler
i put a UINavigationController
2:使用
UIBuiler
我将一个UINavigationController
3: Then i put UITableView
underneath the navigationBar
so it gave me.. 3:然后我将
UITableView
放在navigationBar
下方,因此它给了我。
A: UIViewController-> UINavigationBar + UITableView
答:UIViewController-> UINavigationBar + UITableView
Now i am loading the data in UITableView from a Webservice which is working fine. 现在,我从运行良好的Web服务将数据加载到UITableView中。
I again made a xib with sam config which is 我再次用sam config制作了xib
B: UIViewController-> UINavigationBar + UITableView
B:UIViewController-> UINavigationBar + UITableView
So now when i try to push view B on view A using below code...it wont at all work... 所以现在当我尝试使用下面的代码将视图B推到视图A上时...将无法完成所有工作...
SelectSiteViewController *siteViewController = [[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" bundle:nil];
[self.navigationController pushViewController:siteViewController animated:YES];
When i checked the UINavigationController *nav = self.navigation
当我检查
UINavigationController *nav = self.navigation
nav is 0x0 that is i assume NIL. 导航为0x0,即我假设为NIL。
Can anybody tell me whats wrong in here.. why is it nil...and how can i make it work.. 谁能告诉我这里出什么问题了..为什么没有显示...以及如何使它工作呢..
Thanks a Lot....I would really appreciate any help 非常感谢...。我将非常感谢您的帮助
在UIBuilder中,验证文件的所有者是否引用了UINavigationController。
Got it. 得到它了。
I changed the Architecture a little bit. 我对体系结构做了一些改动。
I made a New UIViewController class with its xib. 我用它的xib制作了一个新的UIViewController类。 And coded new UINavigationController.
并编码了新的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];
} }
And pushing the view in the Switch Statement.... 并在Switch语句中推送视图。
I hope this makes sense ...... 我希望这是有道理的 ......
Thanks jamihash 谢谢jamihash
So you are adding the tableview to the navigation controller right? 因此,您要将tableview添加到导航控制器中了吗? This is how:
这是这样的:
tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:tableView animated:NO];
The tableview gets added as the rootview to the navigation controller. 将tableview作为根视图添加到导航控制器。 And then on selecting a row if you wish to push another viewcontroller use the
然后在选择一行时,如果您想推送另一个ViewController,请使用
self.navigationController pushViewController: newViewController animated:YES];
inside the didSelectRowAtIndex method. 在didSelectRowAtIndex方法中。
NOTE: its UITableViewController *tableView and UINavigationController *navigationController by declaration. 注意:其UITableViewController * tableView和UINavigationController * navigationController通过声明。 So code accordingly for your table.
因此,为您的表编写相应的代码。
why UIViewController-> UINavigationBar + UITableView ? 为什么UIViewController-> UINavigationBar + UITableView?
I suggest you another approach ->UITableViewController A -> Embedded with a Navigation Controller, then after populate tableview you can pass data to ->UITableViewController B by [[self storyboard]instantiateViewControllerWithIdentifier:@"ControllerB"]; 我建议您使用另一种方法-> UITableViewController A->嵌入导航控制器,然后填充表格视图后,您可以通过[[self storyboard] instantiateViewControllerWithIdentifier:@“ ControllerB”]将数据传递给-> UITableViewController B;
then, in storyboard, drop a tableView B and in Identity->storyboard Id put some id. 然后,在情节提要中,放置一个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];
}
hope help 希望帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.