1

我正在尝试在加载 TabBarController 视图之前启动初始登录/注册屏幕。我已经读过将 ModalViewController 放在第一个视图中是一个不错的方法。这可行,但我正在尝试将导航控件添加到 ModalViewController。我遇到以下问题:

1 - 错误:在“AppDelegate”类型的对象上找不到属性“navigationController”

2 - 警告:使用不兼容类型“id”的表达式初始化“AppDelegate *”

这是我的 ModalViewController 上的代码:

-(IBAction)signUpButtonTapped {
// i need to get the control for main navigation controller
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
[appDelegate.navigationController popToRootViewControllerAnimated:NO];
// create object from app main view to push it
SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:@"SignUpViewController" bundle:nil];
[AppDelegate.navigationController pushViewController:signUpViewController animated:YES]; }

有人有想法么?非常感谢!

4

4 回答 4

2

您的代码中有两个问题

1) 使用类名访问 OBJECT。它必须是appDelegate.nav...a对于解决 1 错误来说很小)

[appDelegate.navigationController pushViewController:signUpViewController animated:YES];

2)类型转换分配(用于解决2警告)

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

因此,您的完整工作代码必须为

-(IBAction)signUpButtonTapped {
  // i need to get the control for main navigation controller
  AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
  [appDelegate.navigationController popToRootViewControllerAnimated:NO];
  // create object from app main view to push it
  SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:@"SignUpViewController" bundle:nil];
  [appDelegate.navigationController pushViewController:signUpViewController animated:YES]; 
}
于 2012-08-22T06:42:32.137 回答
0

在您的代码中修改此行

AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];

作为

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

现在试试

于 2012-08-22T06:36:11.933 回答
0

AppDelegate 实例声明如下:

 AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];

改变这个,你很高兴。

于 2012-08-22T06:36:42.710 回答
0

1.确保您的 appDelegate 有一个UINavigationController名为navigationController.

2.代码的第 2 行: AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

3.你的代码的最后一行: [appDelegate.navigat....
不是:
[AppDelegate.navigatio....

于 2012-08-22T06:46:12.890 回答