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
}

对于动态记录,请使用以下链接:

如何在 tableView 中选择特定的复选框,该复选框插入到 iphone 的表格单元界面构建器中

现在这将起作用

于 2011-03-25T11:13:10.680 回答