将行动态添加到UItableView中,最后两行保留为按钮



我面临着向UITableView动态添加行的问题。我想要分别在UITableView的倒数第二行和最后一行上的">Add"one_answers">Save(保存("按钮。我该怎么做?此外,每当触发">Add"按钮时,我都希望在">Add'按钮上方添加一行。如果我的问题不清楚,请告诉我。

您有一些选项。张贴一些代码,以便我们可以给出更好的答案

  1. 当您为tableView设置数据源时,只需在返回行计数时添加numberOfRows加2即可。然后在cellforrowatindexpath中只需检查indexpath并添加必要的按钮。

  2. 您可以将添加和保存按钮放在的单独部分

  3. 您可以忽略单元格行,但可以在UItableview部分的页脚部分添加按钮

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    {
      //Return your view with the two buttons
    }
    
  4. 您可以在tableView页脚中添加按钮,也可以添加

    yourTableView.tableFooterView = yourView; //yourView should contain the two buttons
    

关于添加按钮,请单击。只需更新数据源数组并重新加载该表。

让我们考虑u使用一个数组名称arrData来存储记录,并调用reloadData函数来重新加载表

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return ([arrData count]+2);//+2 for Add and save button
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   //your code for creation of cell

   //Here check for indexpath.row
        if(indexpath.row==[[arrData count]+1])
       {
          //code for Add button
       }
          if(indexpath.row==[[arrData count]+2])
       {
           //code for save button
       }
return cell;
}

但我的建议是不要在UITableViewCell中包含"添加和保存"按钮,因为随着表单元格的增加,"添加"one_answers"保存"按钮会下降。所以每次你需要滚动。

因此,请将其包含在UITableView之下。因此,每次您都可以访问这些按钮

最新更新