0

我有一个视图,我称之为我的方法:

    Twitter *tweet = [[Twitter alloc] initWithNibName:@"Twitter" bundle:nil];

[self presentModalViewController:tweet animated:YES];

视图控制器没有任何问题。现在,当我尝试在 twitter 视图控制器的方法中调用dismissviewcontroller 时,例如:[self dismissModalViewControllerAnimated:NO];

应用程序崩溃了?

即使基本结构是正确的,但仍然应用程序崩溃?为什么呢 ?

4

3 回答 3

2

try: [self.parentViewController dismissModalViewControllerAnimated:NO]; - this is because the modal view controller is presented by the controller that presents the twitter controller and it's one that needs to dismiss the modal controller (which is the twitter controller)

UPDATE: If you're targeting iOS 5+ then use:

[self dismissViewControllerAnimated:NO completion:nil];
//or
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];

else if you want to maintain backward compatibility use:

if([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
{
    [self dismissViewControllerAnimated:NO completion:nil];
}
else
{
    [self dismissModalViewControllerAnimated:nil];
}
于 2012-05-18T09:59:18.130 回答
0

当您在析构函数(dealloc方法)中过度释放某些东西时,通常会发生这种问题。IB 总是添加代码来释放对象,但它不会查看它是否已经存在。

于 2012-05-18T11:13:55.267 回答
0

You need to dimiss the view from the navigation controller. Try this:

[self.navigationController dismissModalViewControllerAnimated:YES];
于 2012-05-18T10:18:42.867 回答