尝试调试“-[UIActionSheet showInView:]”中的“断言失败”错误

发布于 2024-09-04 01:56:03 字数 1248 浏览 4 评论 0原文

我正在学习“开始 iPad 应用程序开发”,并在第 3 章中陷入困境,在第 3 章中我创建了一个与操作表一起使用的项目。

就目前而言,我的应用程序加载到模拟器中效果很好,没有我意识到的错误,但当它运行时,它崩溃并在调试器窗口中显示以下错误:

2010-05-31 19:44:39.703 使用ViewsActionSheet[49538:207] *** 断言 -[UIActionSheet showInView:] 失败, /SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073

2010-05-31 19:44:39.705 使用ViewsActionSheet[49538:207] *** 由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'无效参数 令人满意:查看!= nil

'

我确信这是应用程序根据我对断点的使用而中断的块。

//实现viewDidLoad在加载视图后进行额外的设置(通常是从笔尖加载)。

<代码> - (void)viewDidLoad { UIActionSheet *action = [[UIActionSheet 分配] initWithTitle:@“这是我的操作表!” 代表:自己 取消按钮标题:@“确定” virtualButtonTitle:@“删除消息!” otherButtonTitles:@"选项 1", @"选项 2", @"选项 3", nil];

[action showInView:self.view];  // <-- This line seems to trigger the crash....
[action release];
[super viewDidLoad];

} 我是否

遗漏了一些明显的东西,或者问题是否比此处显示的更多?我已经查看了 showInView 的摘要,但还无法预测其中的任何内容。

我感谢任何和所有的帮助。

问候,

史蒂夫·奥沙利文

I am working through "Beginning iPad Application Development" and am getting hung up in Chapter 3 where I have created a project that works with an Action Sheet.

As it stands now, my application loads into the simulator just fine with no errors that I am aware of, but as it runs, it crashes with the following errors showing up in the debugger window:

2010-05-31 19:44:39.703 UsingViewsActionSheet[49538:207] *** Assertion
failure in -[UIActionSheet showInView:],
/SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073

2010-05-31 19:44:39.705 UsingViewsActionSheet[49538:207] ***
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Invalid parameter not
satisfying: view != nil

'

I am sure that this is the block where the app breaks based upon my use of breakpoints.

//Implement viewDidLoad to do additional setup after loading the view, typically from a nib.


- (void)viewDidLoad {
UIActionSheet *action = [[UIActionSheet alloc]
initWithTitle:@"This is my Action Sheet!"
delegate:self
cancelButtonTitle:@"OK"
destructiveButtonTitle:@"Delete Message!"
otherButtonTitles:@"Option 1", @"Option 2", @"Option 3", nil];

[action showInView:self.view];  // <-- This line seems to trigger the crash....
[action release];
[super viewDidLoad];

}

Am I missing something obvious, or is there more to the problem than is shown here? I have looked at the abstract for showInView and cannot divine anything there yet.

I appreciate any and all asssitance.

Regards,

Steve O'Sullivan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

最好是你 2024-09-11 01:56:03

在 viewDidLoad 方法中,视图并未完全设置。窗口属性未连接。

NSLog(@"View: %@; Window: %@",[self.view description], [self.view.window description]);

可能会显示窗口为 null/nil。

根据您的设计,您可能会幸运地简单地将其在主线程上排队:

-(void) showMyActionSheet
{
    UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"This is my Action Sheet!" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:@"Delete Message!" otherButtonTitles:@"Option 1", @"Option 2", @"Option 3", nil]; 
    [action showInView:self.view];
    [action release];
}

- (void)viewDidLoad 
{
    [super viewDidLoad]; 
    [self performSelectorOnMainThread:@selector(showMyActionSheet) withObject:nil waitUntilDone:NO];
}

Within the viewDidLoad method the view is not setup entirely. The window property is not wired up.

NSLog(@"View: %@; Window: %@",[self.view description], [self.view.window description]);

will probably show that window is null/nil.

Depending on your design, you may have luck with simply queueing it on the main thread:

-(void) showMyActionSheet
{
    UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"This is my Action Sheet!" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:@"Delete Message!" otherButtonTitles:@"Option 1", @"Option 2", @"Option 3", nil]; 
    [action showInView:self.view];
    [action release];
}

- (void)viewDidLoad 
{
    [super viewDidLoad]; 
    [self performSelectorOnMainThread:@selector(showMyActionSheet) withObject:nil waitUntilDone:NO];
}
请止步禁区 2024-09-11 01:56:03

我刚刚遇到了同样的问题。
我正在将现有的 iPhone 应用程序转换为通用运行。
我有几个名为 UIAlertViews 的按钮工作正常,但我有一个调用操作表的按钮。
它产生了同样的错误。在我的视图控制器中的 ipadview.xib 的 IB 中,当我应该将其链接到按钮时,我将“视图”错误链接到了窗口。
现在效果很好。
希望这有帮助。
(ps,我是一个完全的新手,所以如果这没有帮助,请原谅)
尼尔

I've just had the same problem.
I was converting an existing iPhone app to run universal.
I have several buttons that called UIAlertViews that work fine but I have a button that calls an actionsheet.
It was generating the same error. In IB in my ipadview.xib in my view controller i had mislinked "view" to window when i should have linked it to the button.
It now works fine.
Hope this helps.
(ps im a complete novice so forgive if this doesnt help)
Neil

驱逐舰岛风号 2024-09-11 01:56:03

我刚刚完成了同一章,本书的作者在这里解决了这个问题 http://p2p.wrox.com/book-beginning-ipad-application-development/79379-ch-3-usingviews-alert-actionsheet.html 但如果如果是你,我会投票选择 Eiko 的响应作为答案,因为它实现了示例所需的行为,而作者让你创建一个按钮,在应用程序启动后单击该按钮即可查看工作表。

I was just working through the same chapter and the book's author addresses it here http://p2p.wrox.com/book-beginning-ipad-application-development/79379-ch-3-usingviews-alert-actionsheet.html though if I were you I would vote Eiko's response as the answer since it accomplishes the behavior the example is going for, whereas the authors has you create a button that you clicked after the application launches to see the sheet.

笙痞 2024-09-11 01:56:03

对于后来接触此主题的人来说,这仍然是 5.0 (9A334) iPad 模拟器和物理设备 (iPad) 中的问题。

Eiko 的答案仍然正确。

Just for any late comers to this topic, this is still an issue in 5.0 (9A334) iPad simulator and physical devices (iPads).

The answer by Eiko remains correct.

日久见人心 2024-09-11 01:56:03

我最近修复了 ActionSheet 的断言失败,如下所示:

UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
    if ([window.subviews containsObject:self.view]) {
        [action showInView:self.view];
    } else {
        [action showInView:window];
    }

它对我来说效果很好。

I have fixed assertion failure for ActionSheet recently like this:

UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
    if ([window.subviews containsObject:self.view]) {
        [action showInView:self.view];
    } else {
        [action showInView:window];
    }

It works fine for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文