1

我在下面有一些来源。

- (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 错误。我能做些什么 ?

4

1 回答 1

2

正确读取控制台输出,默认情况下,每个视图都有标签“0”,因此它可能会崩溃,因为它正在获取除 uibutton 之外的其他视图,并且可能是该视图没有titleLabel属性。因为它是UIButton 的属性。

于 2012-04-24T06:28:38.990 回答