Sos*_*van 3 objective-c uiactionsheet ipad
我正在完成"开始iPad应用程序开发",并且在第3章中我已经创建了一个与Action Sheet一起工作的项目.
就像现在一样,我的应用程序很好地加载到模拟器中没有我知道的错误,但是当它运行时,它会在调试器窗口中显示以下错误而崩溃:
2010-05-31 19:44:39.703 UsingViewsActionSheet [49538:207]***断言失败 - [UIActionSheet showInView:],/ SourceCache/UIKit_Sim/UIKit-1145.66/UIAlert.m:7073
2010-05-31 19:44:39.705 UsingViewsActionSheet [49538:207]***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效的参数不满足:view!= nil
"
我确信这是应用程序基于我使用断点而中断的块.
//实现viewDidLoad在加载视图后执行其他设置,通常是从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];
Run Code Online (Sandbox Code Playgroud)
}
我错过了一些明显的东西,还是问题比这里显示的更多?我已经查看了showInView的摘要,并且还无法对其进行任何修改.
我感谢任何和所有的支持.
问候,
史蒂夫奥沙利文
Eik*_*iko 11
在viewDidLoad方法中,视图未完全设置.窗口属性未连线.
NSLog(@"View: %@; Window: %@",[self.view description], [self.view.window description]);
Run Code Online (Sandbox Code Playgroud)
可能会显示窗口为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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5743 次 |
| 最近记录: |