2012-06-16 42 views
0

我有一個使用的過渡文件從頁面翻轉到頁面的應用程序。我使用ARC並且在5.1上工作得很好,但是在4.3模擬器上一直崩潰。查看線程和儀器的擴展細節,它指向2行代碼(如下所示),並顯示錯誤:EXC_BREAKPOINT(code = EXC_I386_BPT)。看起來像UIViewController正在被釋放。不知道如何解決這個問題。預先感謝您提供的任何幫助!消息發送到的dealloc的UIViewController,錯誤:EXC_BREAKPOINT(代碼= EXC_I386_BPT)

@synthesize containerView = _containerView; 
@synthesize viewController = _viewController; //ERROR LINE#1 

- (id)initWithViewController:(UIViewController *)viewController 
{ 
    if (self = [super init]) 
    { 
     _viewController = viewController; 
    } 
    return self; 
} 

- (void)loadView 
{ 
    self.wantsFullScreenLayout = YES; 
    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
    view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 
    self.view = view; 

    _containerView = [[UIView alloc] initWithFrame:view.bounds]; 
    _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; 
    [self.view addSubview:_containerView]; 

    [_containerView addSubview:self.viewController.view]; 
} 

- (void)transitionToViewController:(UIViewController *)aViewController 
        withOptions:(UIViewAnimationOptions)options 
{  
    aViewController.view.frame = self.containerView.bounds; 

    [UIView transitionWithView:self.containerView 
         duration:0.65f 
         options:options 
        animations:^{ [self.viewController.view removeFromSuperview]; 
         [self.containerView addSubview:aViewController.view];} 
        completion:^(BOOL finished) 
    //ERROR LINE#2     { self.viewController = aViewController;}]; 
} 
+0

你在哪裏打電話transitionToViewController? –

+0

我爲每個頁面都有一個ViewController。這是我用來調用它的代碼行。 TitlePageViewController * tpvc = [[TitlePageViewController alloc] init]; AppDelegate * appDelegate = [UIApplication sharedApplication] .delegate; [appDelegate.transitionController transitionToViewController:TPVC withOptions:UIViewAnimationOptionTransitionCurlUp]; – ctw

回答

0

您不應該將視圖從其各自的視圖控制器之下切換出。你可能會得到它的工作,但它是脆弱的,至多。

如果你想將來證明你的代碼,你應該視圖控制器之間的轉換,讓他們處理自己的看法,但包裹,在所需的動畫,如果你不喜歡默認的動畫。所以,你應該:

  1. 只是做簡單的presentViewControllerpushViewController去下一個控制器和dismissViewControllerpopViewController返回;或

  2. 在iOS 5中,你可以做你自己的容器視圖控制器(見session 102 in WWDC 2011或看到的view controller containment in the UIViewController reference的討論),然後你可以transitionFromViewController

如果我們知道更多關於您的應用程序流程的原因,爲什麼您要做的是您正在做的事情,我們可能會進一步提供建議。

+0

感謝您的幫助。該應用程序是一個簡短的故事書。我決定使用transitionController,因爲我認爲它提供了更好的動畫選項。但由於它看起來是一個脆弱的設計,我可以回到簡單的pushViewController方法。感謝WWDC的鏈接,我會仔細研究一下,看看是否有其他一些可能有用的選項。 – ctw

+0

@ctw如果你的直覺是你不想在頁面之間推送視圖控制器,那麼你可能是對的。如果我想去上學,我可能會爲顯示的頁面創建自己的UIView子類,並使用該子類爲頁面之間的轉換創建動畫,而不是推送視圖控制器。順便說一句,它可能是值得檢查出的[頁面視圖控制器(http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/PageViewControllers.html),太。 – Rob

+0

@Ryan - 是的PageViewController正是我想要做的!但我無法弄清楚如何使用自己的視圖控制器設置每個頁面。看起來每個頁面只是一個靜態頁面......並不是我可以在每個頁面上都有自己的xib設置一個新的視圖控制器的地方。我非常沮喪,我放棄了。我想我會回去再試一次。 – ctw

相關問題