我面临着向UITableView
动态添加行的问题。我想要分别在UITableView
的倒数第二行和最后一行上的">Add"one_answers">Save(保存("按钮。我该怎么做?此外,每当触发">Add"按钮时,我都希望在">Add'按钮上方添加一行。如果我的问题不清楚,请告诉我。
您有一些选项。张贴一些代码,以便我们可以给出更好的答案
-
当您为
tableView
设置数据源时,只需在返回行计数时添加numberOfRows
加2即可。然后在cellforrowatindexpath
中只需检查indexpath
并添加必要的按钮。 -
您可以将添加和保存按钮放在的单独部分
-
您可以忽略单元格行,但可以在
UItableview
部分的页脚部分添加按钮- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ { //Return your view with the two buttons }
-
您可以在
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
之下。因此,每次您都可以访问这些按钮