推送到viewcontroller时崩溃 - 目标c

时间:2013-09-12 09:01:03

标签: iphone ios objective-c

当我尝试推送到视图控制器时,我的应用程序崩溃了。只有当我们尝试导航到另一个页面(push和presentModal)时才会发生这种情况。我还检查了视图控制器中应该被推送的IBOutlets和其他连接。但无法找到线索。这是我执行推送的代码:

PhoneBookView *phoneBook = [[PhoneBookView alloc] initWithNibName:@"PhoneBook" bundle:[NSBundle mainBundle]];

[self.navigationController presentModalViewController:phoneBook animated:YES];

7 个答案:

答案 0 :(得分:1)

为您提供信息'presentModalViewController:animated:' is deprecated: first deprecated in iOS 6.0

试试这个:

PhoneBookView *phoneBook = [[PhoneBookView alloc] initWithNibName:@"PhoneBookView" bundle:[NSBundle mainBundle]];
[self.navigationController presentViewController:phoneBook animated:YES completion:nil];

答案 1 :(得分:0)

PhoneBookView *phoneBook = [[PhoneBookView alloc] initWithNibName:@"PhoneBook" bundle:[NSBundle mainBundle]];

[self.navigationController presentModalViewController:phoneBook animated:YES];

使用代码存在视图控制器

PhoneBookView *phoneBook = [[PhoneBookView alloc] initWithNibName:@"PhoneBook" bundle:[NSBundle mainBundle]];

[self presentModalViewController:phoneBook animated:YES];

并推送视图控制器

PhoneBookView *phoneBook = [[PhoneBookView alloc] initWithNibName:@"PhoneBook" bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:phoneBook animated:YES];

答案 2 :(得分:0)

 PhoneBookView *phoneBook = [[PhoneBookView alloc] initWithNibName:@"PhoneBook" bundle:[NSBundle mainBundle]];
 UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:phoneBook];

[self.navigationController presentModalViewController:nav animated:YES];

如果要在显示视图后执行推送操作,则需要将UINavigation控制器添加为该呈现视图的根视图控制器..

快乐的编码......

答案 3 :(得分:0)

[self.navigationController presentModalViewController:phoneBook animated:YES];不推荐使用此方法

相反,您可以使用

[self presentViewController:<#(UIViewController *)#> animated:<#(BOOL)#> completion:<#^(void)completion#>]

self presentViewController:phoneBook animated:YES completion:nil]

答案 4 :(得分:0)

你可以试试这个,不需要指定包,

PhoneBookView *phoneBook=[[PhoneBookView alloc] initWithNibName:@"PhoneBook" bundle:nil];

[self.navigationController pushViewController:phoneBook animated:YES];

答案 5 :(得分:0)

重置iOS模拟器,退出xcode并重新启动它,让我们看看它是否对您有所帮助,这似乎不是您的代码错误,而是xcode或模拟器。

答案 6 :(得分:-2)

尝试使用以下内容:

PhoneBookView * phoneBook = [[PhoneBookView alloc] initWithNibName:@“PhoneBookView”bundle:[NSBundle mainBundle]];