任何人都有任何想法,这意味着如何解决?
*断言失败 - [UIActionSheet showInView:],/ SourceCache / UIKit_Sim / UIKit-1912.3 / UIActionSheet.m:4630 2012-03-02 17:12:34.643战略&风险[66854:15803] * 由于终止应用程序 未捕获的异常'NSInternalInconsistencyException',原因: '无效参数不满足:view!= nil'
更新:只会偶尔发生:
更新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;
}
}
答案 0 :(得分:2)
如果应用程序中有标签栏,则应使用以下方法显示操作表。
[actionsheet showFromTabBar:]
或
[actionsheet showFromToolbar:]
您遇到的断言失败是因为您的应用程序和iPhone中可能有一个标签栏,您可能正在使用该方法显示操作表:
[actionsheet showInView:]
如果是这种情况,那么你应该使用:
[actionsheet showFromTabBar:]
希望这会对你有所帮助。
修改-2:强>
[actionsheet showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
EDIT-3:
答案 1 :(得分: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:以防万一,虽然这个视图控制器被重用,所以它永远不会被调用。
故事的道德:在解除分配之前删除@Observer!
- (void)viewDidUnload
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
答案 2 :(得分:0)
你还没说你确定self.view
!=无。似乎很清楚,这是第一件事。或者检查何时挂在调试器中。