xcode 向表中添加行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8831390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:58:44  来源:igfitidea点击:

Adding rows to a table

xcodetableview

提问by MacUser

I have a table with objects added with NSArray called listOfConjProcedures I want to use an insert control that appears above the top row in the table to add rows to my table when tapping the edit button in a UInavigation controller and I cannot find a good sample code. The edit function looks like this:

我有一个用 NSArray 添加的对象的表,称为 listOfConjProcedures 我想在点击 UInavigation 控制器中的编辑按钮时使用出现在表顶行上方的插入控件将行添加到我的表中,但我找不到好的示例代码. 编辑功能如下所示:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([tableView isEditing])
        return [listOfConjProcedures count] + 1;
    else
        return [listOfConjProcedures count];    
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [listOfConjProcedures removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.

          }            
        }

I don't know how to proceed with the insert function to introduce a new row when the edit button is tapped (At the bottom of the posted code). Thank you in advance.

我不知道如何使用插入功能在点击编辑按钮时引入新行(在发布的代码底部)。先感谢您。

回答by Balakrishnan Mca

This links helps you for insert new row link1link2link3

此链接可帮助您插入新行link1 link2 link3