来自First Tab Bar View的iPhone ModalViewController

时间:2012-08-22 06:28:55

标签: uitabbarcontroller modalviewcontroller

我正在尝试在我的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 个答案:

答案 0 :(得分:2)

您的代码中存在两个问题

1)使用类名访问OBJECT。它必须是 appDelegate.nav ... (解决1个错误的小a

[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]; 
}

答案 1 :(得分:0)

在您的代码中修改此行

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

作为

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

立即尝试

答案 2 :(得分:0)

AppDelegate实例声明如下:

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

改变这一点,你好了。

答案 3 :(得分:0)

1.确保您的appDelegate有一个名为UINavigationController的{​​{1}}属性。

2.你的代码的第2行: navigationController

你的代码的第7行: AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
不:[appDelegate.navigat....