美文网首页
iOS开发之"崩溃"

iOS开发之"崩溃"

作者: 师弟出马 | 来源:发表于2016-06-08 02:28 被阅读41次

在开发中,系统难免会出现崩溃的情况,总是让我们也很崩溃

屏幕快照 2016-03-03 下午10.08.23.png

今天我们可以自己创建一个崩溃信息,也可以方便我们在以后的开发中进行代码的调试

很简单只需要调用系统为我们封装好的类NSException

首先我们需要创建一个UIButton控件

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 100, 200, 50);
    button.backgroundColor = [UIColor cyanColor];
    [button setTitle:@"崩溃" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

//实现UIButton的点击事件,并且在点击的时候让系统崩溃

-(void)buttonClicked {
    @throw [NSException exceptionWithName:@"CQ_Error" reason:@"海贼王" userInfo:nil];
}

效果如下图

屏幕快照 2016-03-03 下午10.14.15.png

相关文章

网友评论

      本文标题:iOS开发之"崩溃"

      本文链接:https://www.haomeiwen.com/subject/cnsylttx.html