2012-03-02 101 views
0

任何人有任何想法這意味着什麼,以及如何整理出來?聲明失敗 - [UIActionSheet showInView:]

*斷言故障 - [UIActionSheet showInView:],/SourceCache/UIKit_Sim/UIKit-1912.3/UIActionSheet.m:4630 2012-03-02 17:12:34.643策略&風險[66854 :15803] *終止應用程序由於 未捕獲的異常 'NSInternalInconsistencyException',原因是: '無效的參數並不令人滿意:查看=零!'

更新:它只是發生零星:

更新2:我沒有在我的應用程序標籤欄或工具欄

更新3:我已經改變使用showInView代碼:和我得到完全相同的錯誤信息。

- (void)displayAddEntityActionSheet { 

    //Convert the tap location to this view's coordinate systems 
    CGRect buttonTappedRect = [self.currentNodeView convertRect:self.currentNodeView.frame toView:self.view]; 

    UIActionSheet *actionSheet; 

    switch (self.currentNode.nodeType) { 
     case NodeTypeEntity: 
      actionSheet = [[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil 
             destructiveButtonTitle:nil otherButtonTitles:@"Entity", @"Objective", nil] autorelease]; 

      [actionSheet showFromRect:buttonTappedRect inView:self.view animated:YES]; 
      break; 
     case NodeTypeObjective: 
      actionSheet = [[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil 
             destructiveButtonTitle:nil otherButtonTitles:@"Risk", @"KPI", nil] autorelease]; 

      [actionSheet showFromRect:buttonTappedRect inView:self.view animated:YES]; 
      break; 
     case NodeTypeRisk: 
      actionSheet = [[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil 
             destructiveButtonTitle:nil otherButtonTitles:@"KRI", @"Control", nil] autorelease]; 

      [actionSheet showFromRect:buttonTappedRect inView:self.view animated:YES]; 
      break; 
     case NodeTypeControl: 
      actionSheet = [[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil 
             destructiveButtonTitle:nil otherButtonTitles:@"KCI", nil] autorelease]; 

      [actionSheet showFromRect:buttonTappedRect inView:self.view animated:YES]; 
      break; 
     default: 
      break; 
    } 
} 
+1

你能告訴我們你創建actionSheet的代碼嗎? – EmilioPelaez 2012-03-02 16:39:14

+0

除非您發佈一些代碼,否則我們無法說出任何內容。 – akashivskyy 2012-03-02 16:52:34

+0

@TheLearner請參考我的回答,我認爲答案會幫助你解決這個斷言失敗。 – 2012-03-02 16:53:58

回答

1

終於發現是什麼導致了錯誤,下面的代碼被多次調用,這反過來調用了我原來的帖子中的方法,並且這個視圖控制器永遠不會被釋放,但即使它是我沒有刪除它作爲一個觀察員這些通知:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 

    if (self) { 

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addNewEntity:) name:@"addSubEntity" object:nil]; 
    } 

    return self; 
} 

所以我有固定的調用init反覆和安全起見,我也呼籲removeObserver的bug:以防萬一,雖然這個視圖控制器重複使用,因此不會被調用。

故事的道德:取消分配前的removeObserver!

- (void)viewDidUnload 
{ 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
} 
2

,如果你在你的應用程序中的標籤欄應使用以下用於顯示動作片的方法。

[actionsheet showFromTabBar:] 

[actionsheet showFromToolbar:] 

這你面對斷言失敗是因爲你可能在你的應用程序,並在iPhone,你可能會使用的方法顯示動作片上的標籤欄:

[actionsheet showInView:] 

如果是這種情況,那麼你應該使用:

[actionsheet showFromTabBar:] 

希望這可以幫助你。

EDIT 2:

[actionsheet showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES]; 

編輯-3:

UIActionSheet Crashes on iPad/not iPhone

http://forums.macrumors.com/showthread.php?t=997125

+0

我不希望它從標籤欄或工具欄出現,雖然 – TheLearner 2012-03-02 17:01:02

+0

@TheLearner:它不會從tabBar中出現,它會顯示爲正常,但在系統級別通知操作表後面有一個標籤欄它。 – 2012-03-02 17:47:30

+0

所以它會出現在正確的地方,沒有指定任何直角座標? – TheLearner 2012-03-05 10:40:30

0

你還不說,你確信self.view =零!看起來很清楚這是第一件要做的事情。或者檢查何時掛在調試器中。