我在下面有一些资源。
- (void)Button:(UIButton *)button {
NSString *imageName = ((UIButton *)[self.view viewWithTag:button.tag]).titleLabel.text;
}
- (void)viewDidLoad {
NSMutableArray *_array = [[NSMutableArray alloc] init];
NSInteger iCount = [_array count];
for (i = 0; iCount > i; i++) {
UIButton *btn = [[UIButton alloc] init];
btn.titleLabel.text = [[_array objectAtIndex:i] objectForKey:@"FILE"];
btn.tag = i;
[btn addTarget:self action:@selector(Button:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[btn release];
}
当我访问带有 0 索引标记的 Button 方法时,出现 SIGABRT 错误。 我能做什么?
最佳答案
正确阅读你的控制台输出,默认情况下每个 View 都有标签“0”,所以它可能会崩溃,因为它正在使用除 uibutton 之外的其他 View ,并且可能是该 View 没有 titleLabel属性。因为它是UIButton的属性。
关于objective-c - 为什么这会导致 SIGABRT 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10292699/