向表中添加行

发布于 2024-12-26 21:45:45 字数 1115 浏览 2 评论 0原文

我有一个用 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 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:

- (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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘味果▽酱 2025-01-02 21:45:45

此链接可帮助您插入新行 link1 链接2 链接3

This links helps you for insert new row link1 link2 link3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文