Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView with custom cells not entering editing mode

I have a UITableView with custom UITableViewCells.

  1. The table has two sections, the first section has a single row with a UITextField and can only be edited in terms of the text. This section & row cannot be edited from a UITableView perspective

  2. The second section is a list of cells that are generated from an NSArray. These cells are once again custom UITableViewCells comprising of two UITextFields. These cells can be edited from a UITableView perspective, in the sense that the user can delete and insert rows.

  3. In my designated initializer I have specified self.tableView.editing = YES, also I have implemented the method canEditRowAtIndexPath to return YES.

Problem Statement

The table view does not enter editing mode. I do not see the delete buttons or insert buttons against the rows of section 2. What am I missing?

like image 672
ChicagoSky Avatar asked Jun 16 '11 04:06

ChicagoSky


1 Answers

just a suggestion, check whether your controller fit to these requirements :

i use usual UIViewController and it works fine - you need to :

  1. make your controller a delegate of UITableViewDelegate, UITableViewDataSource
  2. implement - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  3. programmatically add EDIT button - self.navigationItem.rightBarButtonItem = self.editButtonItem (if you add EDIT button from builder you will need to call setEditing : YES manually)

Piece of code :)

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return UITableViewCellEditingStyleDelete;
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{
    [super setEditing:editing animated:animated];
    [self.tableView setEditing:editing animated:YES];
}

- (void)tableView 
    :(UITableView *)tableView didSelectRowAtIndexPath 
    :(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

// do not forget interface in header file

@interface ContactsController : ViewController<
    UITableViewDelegate,
    UITableViewDataSource>

Profit!

like image 190
Anonymous Avatar answered Oct 11 '22 18:10

Anonymous