Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing insert rows in a UITableView
    text
    copied!<p>I'd like my UITableView to behave like the the table in the Contacts editor, i.e. the user should hit Edit and an "add new category" row should appear at the bottom of each section.</p> <p>I'm using the below code to do this, but the problem is that there is no smooth transition as there is in Contacts. Instead, the new row suddenly appears. How can I get the animation?</p> <p>Also, how do I respond to clicks on the "add new category" row? The row is not clickable in my current implementation.</p> <p>Do I need to reload the data when the user starts editing? I am doing this because otherwise the insertion rows are never drawn.</p> <p>Thanks.</p> <pre><code>- (void)setEditing:(BOOL)editing animated:(BOOL)animated { [super setEditing:editing animated:animated]; [self.tableView setEditing:editing animated:animated]; [tableView reloadData]; } - (NSInteger)tableView:(UITableView *)_tableView numberOfRowsInSection:(NSInteger)section { // ... if( self.tableView.editing ) return 1 + rowCount; } - (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // ..... NSArray* items = ...; if( indexPath.row &gt;= [items count] ) { cell.textLabel.text = @"add new category"; } // ... return cell; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { NSArray* items = ...; if( indexPath.row == [items count] ) return UITableViewCellEditingStyleInsert; return UITableViewCellEditingStyleDelete; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload