1

ユーザーがUIButtonテーブルビュー (テーブルビューには各行に複数のボタンがあります) をクリックすると、別のビューが表示されます。ユーザーが他の UIView の [完了] ボタンをクリックした後に、このボタンの画像を変更したいと考えています。どうやってやるの?私は初心者です。コードを教えてください。前もって感謝します。

更新コード:

テーブルビューのコード:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%d",indexPath.section,indexPath.row];

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom];
        [market addTarget:self action:@selector(marketPressedAction:) forControlEvents:UIControlEventTouchDown];

        [market setTag:3000];
        [market setFrame:CGRectMake(200, 6, 30, 30)];
        [cell.contentView addSubview:market];

    }

   for (UIButton *button in [cell subviews]) { // change name of table here
    if ([button isKindOfClass:[UIButton class]]) {
        button.tag = indexPath.row;
        [button setImage:[UIImage imageNamed:@"Marketplace.png"] forState:UIControlStateNormal];
    }
}


    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    _tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);

    return cell;
}

[開く] ボタンのコード (ユーザーがクリックして別のビューを表示するボタン)

    - (void)marketPressedAction:(id)sender
{

    UIButton *button = (UIButton *)sender;
    buttontag = button.tag;
    NSLog(@"Market button click at row %d",buttontag);
}

[完了] ボタンのコード:

 -(void)submitMarket
{
    for (UIButton *button in [_tableView subviews]) { // change name of table here
        if ([button isKindOfClass:[UIButton class]]) {
            if (button.tag == buttontag) {
                [button setBackgroundImage:[UIImage imageNamed:@"MarketplaceSelect.png"] forState:UIControlStateNormal];
            } 
        } 
    }
}
4

3 に答える 3

0

ボタンの選択状態に別の画像を設定し、[完了] ボタンをクリックした後、ボタンの選択状態を設定するだけです。

  [yourButton setBackgroundImage:someImge forState:UIControlStateSelected];

完了ボタンの後:

  [yourButton setSelected:YES];

または、前に使用するUIControlStateSelected場合は、他の状態も使用できます。またはユーザーの状態でさえ -UIControlStateApplication

于 2013-08-15T07:06:07.247 に答える