在UITableView中添加一行以添加新项? [英] Add a row to UITableView for adding new item?

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

问题描述

为了向用户提供UI以将新项目添加到我的表视图中,我想在视图处于编辑模式时在表中的指定位置(例如最后一行)的位置添加新行(我有视图导航栏右侧的编辑按钮).新行的左侧将具有添加按钮指示器,右侧将具有披露附件箭头.当视图不在编辑模式下时,不应显示此添加行.

In order to provide UI for user to add new items to my table view, I would like to add a new row in my table at a specified location (last row for example) when the view is in edit mode (I have a edit button on the view's navigation bar right side). This new row will have a add button indicator on the left side and disclosure accessory arrow on the right. When the view is not in edit mode, this add row should not be displayed.

我不确定是否应该覆盖:

I am not sure if I should overwrite:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{...}

我在其中调用UITableView的方法:

where I call the UITableView's method:

insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:
 (UITableViewRowAnimation)animation

要插入新行?

我的理解是,此调用可能会在表视图中添加新行.表格视图的数据源来自CoreData存储.不确定这是否会导致数据存储和表视图中的数据数量不一致?如果可以,并且必须在表格视图中管理行,如何在新行中添加左添加指示器和左显示箭头?

My understanding is that this call may add a new row into the table view. The table view's data source is from CoreData storage. Not sure this may cause inconsistent numbers of data in the data store and table view? If it is OK and I have to manage rows in the table view, how can I add left add indicator and left disclosure arrow to the new row?

另一个问题是,如果我可以插入新行作为添加行",那么当表格视图不在编辑模式下时是否应该将其删除?

Another question is that if I can do it to insert a new row as Add row, should I remove it when the table view not in edit mode?

只想知道我是否走在正确的轨道上.

Just want to know if I am on the right track.

推荐答案

– insertRowsAtIndexPaths:withRowAnimation:将在TableView中添加一行.该行将一直存在于TableView中,直到将其删除或重新加载数据为止.如果退出编辑模式,则该行的外观将通过以下方法发送到DataSource对象:

– insertRowsAtIndexPaths:withRowAnimation: will add a row to the TableView. That row will live in the TableView until it is removed or the data is reloaded. If you exit edit mode, the appearance of that row will be sent to the DataSource object with this method:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

退出编辑模式时,将触发DataSource对象,使您有机会使事情回到一致状态.覆盖setEdit以及在超级调用之前插入和删除行可能比确定commitEditingStyle DataSource方法的接口更容易-有点奇怪.

When editing mode is exited, the DataSource object will be triggered to give you the opportunity to get things back into a consistant state. Over-riding setEditing and inserting and removing the row prior to the super call is probably easier than working out the interface to the commitEditingStyle DataSource method - it's a little odd.

这篇关于在UITableView中添加一行以添加新项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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