テーブル行のボタンに、データベースの値に応じて異なるタイトルを表示させたい。
しかし、私は各ボタン、つまりボタン0、ボタン1などを一意に識別する際に問題に直面しています。
ボタンはテーブルの行にあることに注意してください。
テーブル行のボタンに、データベースの値に応じて異なるタイトルを表示させたい。
しかし、私は各ボタン、つまりボタン0、ボタン1などを一意に識別する際に問題に直面しています。
ボタンはテーブルの行にあることに注意してください。
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
}
テーブル indexpath.row + 独自の値 (0,1,2...) を各ボタンのタグとして使用できます。よくわかりませんが、少なくとも試すことができます。
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の特定のチェックボックスを選択する方法
これでうまくいきます