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

ビューでDidLoad

myButtons = [[NSMutableArray alloc] init];

内部 if 条件

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