Insert, delete, and reorder the
UITableViewCells
of a
UITableView.
The last cell is always green,
the others are red.
Why is one of the reordering controls missing?
AppDelegate
TableViewController
TableViewController.
//Will be called when the Edit/Done button is pushed.
- (void) buttonPushed: (id) sender
{
//Do what the Edit/Done button normally does.
[self.tableView setEditing: !self.tableView.editing animated: YES];
((UIBarItem *)sender).title =
self.tableView.editing ? @"Done" : @"Edit";
//In addition, dismiss the keyboard.
if (changing != nil) {
UITableViewCell *cell =
[self.tableView cellForRowAtIndexPath: changing];
UITextField *textField = [cell.contentView.subviews lastObject];
[textField resignFirstResponder];
[textField removeFromSuperview];
changing = nil;
}
}
Add the following statements to the end of the
viewDidLoad
method of the
TableViewController.
self.editButtonItem.target = self; self.editButtonItem.action = @selector(buttonPushed:);
tableView:moveRowAtIndexPath:toIndexPath:
method of the
TableViewController.
--If the cell that was just dragged was the bottom cell, if (fromIndexPath.row == lines.count - 1) { [tableView reloadData]; }