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

今天我们可以自己创建一个崩溃信息,也可以方便我们在以后的开发中进行代码的调试
很简单只需要调用系统为我们封装好的类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];
}
效果如下图

网友评论