向现有UITableView节添加行 [英] Add rows to existing UITableView section

查看:113
本文介绍了向现有UITableView节添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取一些示例代码,如何向现有的 UITableView 添加行。我试图使用 insertRowsAtIndexPaths:函数。

I am trying to get some sample code on how I would add rows to an existing UITableView. I am trying to use the insertRowsAtIndexPaths: function.

    [tableView insertRowsAtIndexPaths:addindexes withRowAnimation:UITableViewRowAnimationTop];

任何想法如何这些索引工作,如何添加到现有的部分,

Any ideas how these indexes work and how I can add to an existing section or, if I don't have a section, then create a new section?

推荐答案

您必须创建一个索引路径数组为 -

You have to create an array of indexpaths as -

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

例如,如果要在第0节插入第2行,为区段0中的行1创建索引路径,并在表视图上调用insertRowsAtIndexPaths,它将在区段中插入第2行。

for example if you want to insert 2nd row in section 0 and already have 1 row in section 0 then create an index path for row 1 in section 0 and call the insertRowsAtIndexPaths on table view, it will insert 2nd row in section.

如果表视图中没有节,你应该使用一个数据源的int来给表格视图中没有节,在这个使用 -

If there is no section in table view then you should use an int for data source to give no of sections in table view, in this use -

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return noOfSection; //here section is as int which is initially zero
}

noOfSection将为零,那么表中将没有段,那么当你想添加段增加你的int值为1并调用 [tableView reloadData];

and initially your int "noOfSection" will be zero then there will be no section in table, then when you want to add section increase your int value by 1 and call [tableView reloadData];

这篇关于向现有UITableView节添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆