我希望表格行中的按钮根据数据库值显示不同的标题。
但是我在唯一识别每个按钮(即按钮 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
}
对于动态记录,请使用以下链接:
如何在 tableView 中选择特定的复选框,该复选框插入到 iphone 的表格单元界面构建器中
现在这将起作用