开发者

Add a row to UITableView for adding new item?

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)setEditi开发者_开发百科ng:(BOOL)editing animated:(BOOL)animated{...}

where I call the UITableView's method:

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

to insert a new row?

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: 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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜