在我的下面的代码中,我收到一条错误,说“Property”navigationController“找不到'iPhoneFirstPageView *'类型的对象。这之前在另一个项目中有效,但它在这个XIB中不起作用。任何想法?
-(IBAction)Twitter {
TwitterViewController *twitter = [[TwitterViewController alloc] initWithNibName:nil bundle:nil];
//[self presentViewController:twitter animated:YES completion:NULL];
//[self presentModalViewController:twitter animated:YES];
[self.navigationController pushViewController:TwitterViewController animated:YES];
}
答案 0 :(得分:1)
你的第一个问题就是这一行:
[self.navigationController pushViewController:TwitterViewController animated:YES];
您正在尝试推送CLASS TwitterViewController
而不是您的对象twitter
您的第二个问题是iPhoneFirstPageView
是UIView
的子类,而不是UIViewController
的子类。新手解决此问题的最简洁方法是在Xcode中创建一个名为iPhoneFirstPageViewController
的新文件,该文件是UIViewController
的子类。
解决方案将初始视图控制器设置如下:
iPhoneFirstPageViewController *firstViewController = [[iPhoneFirstPageViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
////Skip to the method you are trying to write. This will be in iPhoneFirstPageViewController.m
-(IBAction)Twitter
{
TwitterViewController *twitter = [[TwitterViewController alloc] init];
[self.navigationController pushViewController:twitter animated:YES];
}