Objective c UIAlertView引发异常UIAlertButton的内部一致性异常
我一直在努力弄清楚,为什么这样简单的代码会出现错误:Objective c UIAlertView引发异常UIAlertButton的内部一致性异常,objective-c,exception,uialertview,Objective C,Exception,Uialertview,我一直在努力弄清楚,为什么这样简单的代码会出现错误: UIAlertView *alertDialog; alertDialog = [[UIAlertView alloc] initWithTitle:@"Alert button detected" message:@"I need your attention NOW" delegate:self cancelButton
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:@"Alert button detected"
message:@"I need your attention NOW"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Maybe later", @"Never", nil
];
[alertDialog show];
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“正在请求具有nil层的视图()窗口。此视图可能尚未收到initWithFrame:或initWithCoder:。'
我所尝试的:
- 在ios 5和ios 6模拟器中部署时出错
- 如果按钮设置为nil,则该功能有效(未显示任何按钮)
@interface UIButton (UIButton)
它只有init方法。删除此类后,它将正常工作!(或者删除.m中的init方法,该方法可能不完整),尽管我没有将其作为头导入到viewcontroller中,但我正在使用UIAlertView
-(id)init
{
self.backgroundColor = [UIColor blueColor];
return self;
}
谢谢你的帮助。我需要寻找更合适的方法来实现自定义UIButton。您的代码在我的应用程序中正确执行。您在类中做错了什么,请检查您当前的类是否仍在内存中您的代码正常工作,没有任何错误。。。。。。