如何在iPhone的表格视图中添加指定位置的按钮?

如何在iPhone的表格视图中添加指定位置的按钮?,iphone,uitableview,Iphone,Uitableview,你展示这个图像 我需要在7个项目中添加按钮,以便在表视图中持续。 我需要每个按钮的不同的选择器 这是可能的吗? 编辑: 我需要那个想法 当然是的,在cellForRowAtIndexPath方法中保留条件,indexPath.row>6然后添加按钮,否则被忽略 为按钮指定标记值,并根据该标记值执行所需的不同操作 将此项放在单元格中,如箭头所示 if(indexPath.row>6){ UIButton *checkBtnOne= [UIButton buttonWithType:UIB

你展示这个图像

我需要在7个项目中添加按钮,以便在表视图中持续。
我需要每个按钮的不同的
选择器

这是可能的吗?
编辑:

我需要那个想法

当然是的,在cellForRowAtIndexPath方法中保留条件,
indexPath.row>6
然后添加按钮,否则被忽略

为按钮指定标记值,并根据该标记值执行所需的不同操作

将此项放在
单元格中,如箭头所示

if(indexPath.row>6){
 UIButton *checkBtnOne= [UIButton buttonWithType:UIButtonTypeCustom];
        checkBtnOne.frame=CGRectMake(10, 76, 21, 21);
        checkBtnOne.tag=indexPath.row;
        checkBtnOne.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"btn_radio.png"]];
        [checkBtnOne addTarget:self action:@selector(radioButton:) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:checkBtnOne];

}

-(IBAction)radioButton:(id)sender{
    UIButton *checkBtn=(UIButton *)sender;
    // here you will get the tag value so based on that you can perform the action.
    if(checkBtn.tag==6)
       //first button
    else if (checkBtn.tag==7)
      //second button
    else if (checkBtn.tag==8)
      //third button
    .
    .
    .
    .
}

当然是的,在cellForRowAtIndexPath方法中保留条件,
indexath.row>6
然后添加按钮,否则会被忽略

为按钮指定标记值,并根据该标记值执行所需的不同操作

将此项放在
单元格中,如箭头所示

if(indexPath.row>6){
 UIButton *checkBtnOne= [UIButton buttonWithType:UIButtonTypeCustom];
        checkBtnOne.frame=CGRectMake(10, 76, 21, 21);
        checkBtnOne.tag=indexPath.row;
        checkBtnOne.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"btn_radio.png"]];
        [checkBtnOne addTarget:self action:@selector(radioButton:) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:checkBtnOne];

}

-(IBAction)radioButton:(id)sender{
    UIButton *checkBtn=(UIButton *)sender;
    // here you will get the tag value so based on that you can perform the action.
    if(checkBtn.tag==6)
       //first button
    else if (checkBtn.tag==7)
      //second button
    else if (checkBtn.tag==8)
      //third button
    .
    .
    .
    .
}

UITable视图的索引路径方法处的行的单元格中

检查索引
path.row>6
添加按钮并设置按钮
object.tag=索引路径.row
。 因此,您会发现每个按钮都有各自的标签值。
不要忘记为添加的按钮添加目标,并在“使用按钮的添加方法”中分别接收标记值

在UITable视图的索引路径方法处的行的单元格中

检查索引
path.row>6
添加按钮并设置按钮
object.tag=索引路径.row
。 因此,您会发现每个按钮都有各自的标签值。
不要忘记为添加的按钮添加目标,并在“使用按钮的添加方法”中分别接收标记值

您可以为
UITableView
实现两个部分

  • 在第一种情况下,您应该使用具有自定义背景的默认单元格 形象
  • 在第二部分中,您可以使用
    UITableViewCell
    的自定义子类(其中包含
    UIButton
  • 这将使你的代码更干净


    对于特定于第二部分单元格的操作,您可以使用@Sunny的答案实现它。

    您可以为
    UITableView
    实现两个部分

  • 在第一种情况下,您应该使用具有自定义背景的默认单元格 形象
  • 在第二部分中,您可以使用
    UITableViewCell
    的自定义子类(其中包含
    UIButton
  • 这将使你的代码更干净


    对于特定于第二部分单元格的操作,您可以使用@Sunny的答案来实现它。

    这是要添加的最后7个单元格?是的,每个按钮都会自动工作。您是说表中的最后七个单元格?这是要添加的最后7个单元格?是的,每个按钮都会自动工作。您是说表中的最后七个单元格?,我需要在表视图中添加按钮的代码,每个添加的动态按钮都需要自己编写。,-(iAction)radioButton:(id)sender{UIButton*checkBtn=(UIButton*)sender;//在这里,您将获得标记值,以便您可以根据该值执行操作。}此代码仅适用于一个按钮或添加每个按钮?-(iAction)radioButton:(id)sender{UIButton*checkBtn=(UIButton*)sender;//这里您将获得标记值,以便您可以根据该值执行操作。}@sunny如何使用此代码中的第二个购买按钮。@anilmetagg:立即检查。谢谢,@sunny.My work's Done.,我需要表视图中添加按钮的代码,以及每个添加的动态按钮的代码selfly wrok.-(iAction)radioButton:(id)发送方{UIButton*checkBtn=(UIButton*)发送方;//在这里,您将获得标记值,以便您可以基于该值执行操作。}此代码仅工作一个按钮或添加每个按钮?-(iAction)radioButton:(id)发送方{UIButton*checkBtn=(UIButton*))sender;//在这里您将获得标签值,因此您可以根据该值执行操作。}@sunny如何使用此代码中的“第二次购买”按钮。@anilmetagg:现在检查。谢谢,@sunny。我的工作完成了。