我在下面有一些消息来源。
- (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错误。 我该怎么办?
答案 0 :(得分:2)
正确读取你的控制台输出,默认情况下每个视图都有标记'0',所以它可能会崩溃,因为它除了uibutton之外还带有一些其他视图,并且可能是那个视图没有 titleLabel property.Because它是UIButton的属性。