0

テーブル行のボタンに、データベースの値に応じて異なるタイトルを表示させたい。

しかし、私は各ボタン、つまりボタン0、ボタン1などを一意に識別する際に問題に直面しています。

ボタンはテーブルの行にあることに注意してください。

4

4 に答える 4

1

このスレッドを見てくださいhow-to-select-particular-check-box-in-tableview-which-is-inserted-in-table-cell

于 2011-03-25T07:15:24.340 に答える
0

NSObjectプロパティ「タグ」を使用します...例:

 UIButton* myButton;
 myButton.tag = EON; OR myButton.tag = EOFF ;

if(myButton.tag == EON)
{
   myButton.tag = EOFF; 
  //Do As per your requirement 
}
else if(myButton.tag == EOFF)
{
  myButton.tag = EON; 
  //Do As per your requirement 
}
于 2011-03-25T07:20:48.480 に答える
0

テーブル indexpath.row + 独自の値 (0,1,2...) を各ボタンのタグとして使用できます。よくわかりませんが、少なくとも試すことができます。

于 2011-03-25T07:22:37.550 に答える
0

TableView でボタンを一意に識別するには、次の ように各ボタンとすべてのボタンのタグを設定する必要があります

これは、これは間違いなくあなたの問題を解決します:)

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

        UIButton *CameraBreak=[[UIButton alloc]init];
        CameraBreak.frame=CGRectMake(28, 33, 60, 40);
        CameraBreak.tag=indexPath.row;
        [CameraBreak setImage:[UIImage imageNamed:@"Camera.png"] forState:UIControlStateNormal];

        [CameraBreak addTarget:self action:@selector(CameraBtn_Clicked:) forControlEvents:UIControlEventTouchUpInside]; 
        [cell.contentView addSubview:CameraBreak];
            //[CameraBreak release]; 
    return cell;
    }


-(IBAction)CameraBtn_Clicked:(id)sender
{
    NSLog(@"%d",[sender tag]); /This will print the tag of button which you have pressed in TableView
}

動的レコードの場合は、次のリンクを使用します。

iPhoneのテーブルセルインターフェイスビルダーに挿入されたtableViewの特定のチェックボックスを選択する方法

これでうまくいきます

于 2011-03-25T11:13:10.680 に答える