0

我想将所有UIButton viewwithTag :4000(下面的代码)添加UITableView到数组中。我怎样才能做到这一点?请给我任何建议。这是我的代码创建 uitableview :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *identifier = @"identifier";
    cell = [_tableView dequeueReusableCellWithIdentifier:identifier];
    UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease];
        [market setFrame:CGRectMake(200, 6, 30, 30)];
        market.tag = 4000;

        [cell.contentView addSubview:market]; 

   }

    UIButton *marketButton = (UIButton*)[cell.contentView viewWithTag:4000];
    [marketButton setTag:indexPath.row];
    if([sellingArray count]>0)
    {
        NSLog(@"sellingArray %@",sellingArray);
        if([[sellingArray objectAtIndex:indexPath.row] isEqualToString:@"0"]) // nothing
        {
            [marketButton setImage:[UIImage imageNamed:@"Marketplace.png"] forState:UIControlStateNormal];

        }
        else if([[sellingArray objectAtIndex:indexPath.row] isEqualToString:@"2"])  // marketplace
        {
            [marketButton setImage:[UIImage imageNamed:@"MarketplaceSelect.png"] forState:UIControlStateNormal];

        }
    }
    [marketButton setTag:indexPath.row];
    } 
    }
return cell;
}

我想在 reloadData 时更改 Marketbutton 的图像,但它不能更改,所以我想将所有 Marketbutton 添加到数组中,然后为每个按钮设置图像。请帮助我。谢谢

4

2 回答 2

0
NSMutableArray* myButtons = [[NSMutableArray alloc] init];

...

[myButtons addObject: marketButton];
于 2013-08-21T10:39:55.290 回答
0

在 viewDidLoad

myButtons = [[NSMutableArray alloc] init];

内部 if 条件

if(cell == nil){
...
[myButtons addObject: marketButton];
}
于 2013-08-21T10:54:33.750 回答