UINavigationController - 应用程序尝试将零视图控制器推送到目标上,我错过了什么?
我在让导航控制器正常运行时遇到问题!如果我单击 RootViewController 处的表格单元格,它似乎不是下一个 ViewController。
读取错误消息
“应用程序试图将零视图控制器推送到目标上 .”
所以我猜测,我分配了一些错误的东西,我可能错过了我所关注的书中的一些重要内容。
所以问题出现在我的 RootViewController.m 中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UINavigationController *navigationController= [[UINavigationController alloc]init];
switch ([indexPath row]) {
case 0:
[navigationController pushViewController:kundeViewCon animated:YES];
break;
case 1:
[navigationController pushViewController:kalenderViewCon animated:YES];
break;
case 2:
[navigationController pushViewController:wunschViewCon animated:YES];
break;
}
}
在我的 AppDelegate.m 中,我正在执行以下操作来将 RootViewController 设置为 NavigationController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Navigation Controller
RootViewController *rootViewController = [[RootViewController alloc]init];
navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
因此,当我单击单元格时,我得到了我想要推送的所有其他 ViewController。我只是看不到我的错或我错过了什么!?
也许有人可以帮助我并给我提示!那太好了!
I am having problems to get my Navigation Controller to run properly! If I click in the cell of the table at the RootViewController, it appears not the next ViewController.
Error message reads
“Application tried to push a nil view controller on target
.”
So I alloc something wrong, was my guessing, I probably missing something important from the book I follow.
So the problem appears here in my RootViewController.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UINavigationController *navigationController= [[UINavigationController alloc]init];
switch ([indexPath row]) {
case 0:
[navigationController pushViewController:kundeViewCon animated:YES];
break;
case 1:
[navigationController pushViewController:kalenderViewCon animated:YES];
break;
case 2:
[navigationController pushViewController:wunschViewCon animated:YES];
break;
}
}
In my AppDelegate.m I am doing the following things to set a RootViewController as the NavigationController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Navigation Controller
RootViewController *rootViewController = [[RootViewController alloc]init];
navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
So I got all my other ViewControllers that I want to push, when I click in the Cell. I just can not see my fault or what I am missing!?
Maybe someone can help me and give me a hint! That would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
RootViewController
已经有了它的导航控制器 - 您在应用程序委托中创建了它。选择单元格时创建新的导航控制器没有意义。它可能看起来应该更像这样:另外,只需确保当您调用
-pushViewController:animated:
视图控制器(即kundleViewCon
、kalenderViewCon
> &wunschViewCon
) 不为零。它们看起来像实例变量或属性 - 只需确保您在代码的早期分配/初始化它们,例如在-viewDidLoad
中。RootViewController
already has its navigation controller - you created it in the app delegate. Creating a new navigation controller when you select a cell doesn't make sense. It should probably look more like this:Also, just make sure that when you call
-pushViewController:animated:
the view controller (i.e.kundleViewCon
,kalenderViewCon
&wunschViewCon
) are non-nil. They look like instance variables or properies - just make sure you are alloc/initing them earlier in your code, like in-viewDidLoad
.您不必创建新的 UINavigationController。您需要从当前窗口获取控制器。
其中 yourController 是实例化的 UIViewController 之一(kundeViewCon、kalenderViewCon 或 wunschViewCon)
You don't have to create a new UINavigationController. You need to get you controller from the current window.
where yourController is one of your instantiated UIViewController (kundeViewCon, kalenderViewCon or wunschViewCon)
对于 Google 员工:
如果您没有将 ViewController 连接到以下位置,也可能会发生这种情况:
如果您不这样做,那么您的控制器将不会被初始化。
您还需要将ViewController的类重命名为相应的.h / .m文件:
将您的 ViewController 连接到应用程序
通过右键单击并从 ...AppDelegate 拖动到您的 ViewController
释放后点击相应条目:
For Googlers:
This may also happen if you did not connect your ViewController to the:
If you don't do it then your controller des not get initialized.
You also need to rename the class of the ViewController to the corresponding .h / .m file:
Connect your ViewController to the App
By right click and drag from the ...AppDelegate to your ViewController
After releasing click on the corresponding entry: