0

我一直在努力弄清楚为什么使用如此简单的代码会发生错误:

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'而终止应用程序,原因:'请求视图的窗口(<UIAlertButton:0x885f020;frame =(0 0;0 0);transform = [0,0,0,0,0,0] ; alpha = 0; opaque = NO; layer = (null)>) 带有一个 nil 层。此视图可能尚未收到 initWithFrame: 或 initWithCoder:。'

我试过的:

  • 在 ios 5 和 6 模拟器中部署错误
  • 如果按钮设置为nil,它可以工作(没有显示按钮)
4

1 回答 1

0

I am checking the whole project for settings, additional files and delete one by one until I saw one category class that I have created manually earlier:

@interface UIButton (UIButton)

which has only init method. After deleting this class it works! (or deleting the init method in .m which might be incomplete), though I didn't import it as header into the viewcontroller I am using UIAlertView.

-(id)init
{
    self.backgroundColor = [UIColor blueColor];
    return self;
}

Thanks for helps. I will need to look into more appropriate way to implement custom UIButton.

于 2012-12-26T16:40:07.263 回答