2014-04-05 61 views
0

我真的很難過。EXC_BAD_ACCESS(code 2)when calling'presentViewController'

_vc = [[VLCKitViewControlleriPhone alloc]initWithNibName:@"VLCKitViewControlleriPhone" bundle:nil]; 
_vc.modalPresentationStyle = UIModalPresentationFullScreen; 
[self presentViewController:_vc animated:YES completion:nil]; 

給我EXC_BAD_ACCESS(代碼= 2,地址=爲0x0)當presentViewController方法被調用。視圖控制器不是零。它也發生有或沒有筆尖名稱。如果我將presentViewController行註釋掉,其餘的代碼仍會繼續,包括對視圖控制器本身的方法調用。視圖控制器正在運行,我什麼都看不到,因爲它實際上並沒有顯示視圖。

我啓用NSZombies,並試着用Instruments運行它,但它沒有顯示任何東西。該應用程序只是退出和儀器停止,沒有給我任何信息。任何人都知道問題可能是什麼?

+0

是什麼,寫入到控制檯? – user1118321

+0

您是否嘗試在VLCKitViewControlleriPhone的viewDidLoad/WillAppear/DidAppear方法上放置斷點以查看它是否得到了那麼多? – mackworth

+0

你的'VLCKitViewControlleriPhone'是否有'xib'? (因爲,你說如果它有或沒有'nib'的名字,聽起來很奇怪,如果我沒有記錯的話,如果xib不存在就會顯示錯誤 – Larme

回答

0

你可以試試這個

if ([controller respondsToSelector:@selector(setModalPresentationStyle:)]) 
{ 
    [controller setModalPresentationStyle:UIModalPresentationFullScreen]; 
} else { 
    [controller setModalPresentationStyle:UIModalPresentationFormSheet]; 
} 
+1

這個答案沒有意義。你正在檢查'controller'是否響應'setModalPresentationStyle:'並且如果它調用它,這很好。但是如果它沒有迴應,你仍然用不同的說法來調用它。如果它不響應選擇器,用不同的參數調用該選擇器不會讓它神奇地響應 – Chris

相關問題