ios5上dismissViewControllerAnimat

ios5上dismissViewControllerAnimat

本文介绍了在ios5上dismissViewControllerAnimated崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于循环引用,代码是否会崩溃?

Does the code crash, because of a circular reference?

MenuController: UIViewController

- (id)initWithNibName:
{...
TabsController *tabs = [[TabsController alloc] initWithNibName:@"TabsController" bundle:nil];
self.tab = tabs;
....
}

//button pressed:
- (IBAction)showPrefFromMenu:(id)sender {
    // todo change delegate!?
     tab.tabDelegate = self;
    [self presentModalViewController:tab animated:YES];
    //[tab release];
}

// delegate method:
 -(void)myViewDismissed {
    ....
    NSLog(@"tab references: %d", [tab retainCount]) ;

    [self dismissModalViewControllerAnimated:YES];//crash
     ...

}

模态/子类:

TabsController : UIViewController <...>

- (IBAction)dismissTabs:(id)sender {
      ...
    NSLog(@"dismissTabs: sender: %@",sender);
    [self.tabDelegate myViewDismissed];
}

我看到self.tabDelegate是MenuController实例,并且该代码需要请关闭并取消分配TabsController。

As I see the self.tabDelegate is the MenuController instance and on that code want do dismiss and deallocate the TabsController.

虽然在[self.tabDelegate myViewDismissed]之后不再有任何代码;但是如果它不能执行,因为它被解除分配,可能是程序集Ret还是什么指令无法执行?返回声明。

Although it isn't any more code after [self.tabDelegate myViewDismissed]; but if it would be than couldn't execute, because it is deallocated, maybe the assembly Ret or what instruction can't be executed? the return statement.

我会尝试将代理或任何更好的解决方案分开?

I will try to separate the delegate or any better solution?

编辑:
崩溃是典型的:EXC_BAD_ACCESS(代码= 1,地址= 090)
大会看起来像这样:
ldr r1,[r4,r0]

The crash is the typical one: EXC_BAD_ACCESS(code=1,address=090)the Assembly looks like this:ldr r1, [r4, r0]

Edit2:
改变了一下代码,因为在模拟器4.3中没有崩溃,但在5.0它是,现在这里是当前代码:

changed a bit the code, because in simulator 4.3 doesn't crash, but at 5.0 it is, now here is the current code:

- (IBAction)showTab:(id)sender {

    tab.tabDelegate = self;

    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
        [self presentModalViewController:tab animated:YES];
    }
    else{
        NSLog(@"Executing presentViewController (ios>= 5.0)");
        [self presentViewController:tab animated:true completion: nil];
    }

}


 -(void)delegateCallback {

     if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
         [self dismissModalViewControllerAnimated:NO];
     }
     else{
         NSLog(@"Executing dismissViewControllerAnimated (ios>= 5.0)");
         [self dismissViewControllerAnimated:TRUE completion: nil];//crash
     }

}

Edit3截图:

UIWindowController过渡:fromViewController:toViewController:didEndSeelctor行崩溃,原因是:没有parentViewController:

这里的人找到了解决方案,:但在NDA下

UIWindowController transition:fromViewController:toViewController:didEndSeelctor line is crashing, due to: no parentViewController:https://devforums.apple.com/message/451045Guys here found a solution, : https://github.com/ideashower/ShareKit/issues/254 but in under NDA

编辑已解决以重新调整到PushviewController for ios 5.0+
a heplfull链接:

Edit solved to revrite to PushviewController for ios 5.0+a heplfull link: https://stackoverflow.com/a/7767767/529543

- (IBAction)presentViewController:(id)sender {


    tab.tabDelegate = self;

    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
        [self presentModalViewController:tab animated:FALSE];
    }
    else{
        NSLog(@"Executing presentViewController (ios>= 5.0) [tab retainCount]: %d " ,[tab retainCount]);

    // store parent view to able to restore the state:
    parentView = self.view.superview;

    // init a navigation controler and set up:
    navigationController=[[UINavigationController alloc] initWithRootViewController:self];
    [self.view removeFromSuperview];

    [myAppDelegate.window addSubview:navigationController.view];   ///appDelegate is delegate of ur Application

    navigationController.navigationBar.hidden =true;

    [navigationController pushViewController:tab animated:YES];

}

}

并弹出:

-(void)infoViewDismissed {

     if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {

         [self dismissModalViewControllerAnimated:NO];
     }
     else{
         NSLog(@"Executing dismissViewControllerAnimated (ios>= 5.0) ");

         [navigationController popToRootViewControllerAnimated:false];

         [navigationController.view removeFromSuperview];

         [parentView addSubview:self.view];

     }
}

我已解决了我的问题,一个非常丑陋的模式,但是功能...还被告知放弃对ios3的支持:)我不喜欢运行时的GUI架构切换。

I have solved my problem, in a very ugly mode, but is functional...Also told to drop the support for ios3 :) I don't like the GUI architecture switch at runtime at all.

推荐答案

你的问题有点难以理解,但我知道你有一个保留周期:

Your question is a little difficult to understand, but I gather you have a retain-cycle:

ObjectA retains ObjectB
ObjectB retains ObjectA

并且两个对象都没有被释放?

and neither object gets deallocated?

tabDelegate的属性应为:

Your property for the tabDelegate should read:

@property (nonatomic, assign) id tabDelegate;
//                    ^^^^^^-This is the important bit, this stops the retain cycle.

这篇关于在ios5上dismissViewControllerAnimated崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 00:10