2012-03-02 122 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 =零!看起来很清楚这是第一件要做的事情。或者检查何时挂在调试器中。