Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with deleting a UITableViewCell
    primarykey
    data
    text
    <p>This is quite peculiar. I have a UIViewController which implements the UITableViewDelegate and UITableViewDatasource methods. I have attached the delegate and datasource properties and verified that they are being called via logs.</p> <p>My table is using cell prototype cells, it has two sections, and I am using section headers. </p> <p>My tables are working great with the exception of deleting a cell (swipe the cell horizontally, then the delete button should appear). They are properly displaying all the cells that they should, the section headers, custom cells, etc... They just aren't showing the delete button. I can see from my logs that editingStypeForRowAtIndexPath and canEditRowAtIndexPath are being called, however the delete button never appears. </p> <p>However, if I edit cellForRowAtIndexPath to return standard UITableViewCells instead of my subclass, the delete button appears. What would a UITableViewSubclass need to support for this? I've had similar code work in the past without the need for that. </p> <p>A look inside my UITableViewCell subclass: It just hast a few text labels, an image view, and button sitting on top of a background image. Nothing out of the ordinary. </p> <p>Any suggestions welcome</p> <p>Here is my TV code:</p> <pre><code>#pragma mark UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if(section == kInvitesReceivedSection){ return self.invitesReceived.count; } else if(section == kInvitesSentSection){ return self.invitesSent.count; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.section == kInvitesReceivedSection){ SMInviteReceivedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMInviteReceivedTableViewCell"]; cell.invite = self.invitesReceived[indexPath.row]; cell.delegate = self; return cell; } else if(indexPath.section == kInvitesSentSection){ SMInviteSentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMInviteSentTableViewCell"]; cell.invite = self.invitesSent[indexPath.row]; cell.delegate = self; return cell; } // Swap out for these and the delete button will appear // UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; // cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; // return [[UITableViewCell alloc]init]; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { // programmatcially generate UIViews ... return headerView; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if(section == 0 &amp;&amp; self.invitesReceived.count == 0){ return 0; } else if(section == 1 &amp;&amp; self.invitesSent.count == 0){ return 0; } return 44; } - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"%s:%d indexPath=%@", __FUNCTION__, __LINE__, indexPath); return UITableViewCellEditingStyleDelete; } // This is called when the user swipes across a cell and presses delete. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"%s:%d indexPath=%@", __FUNCTION__, __LINE__, indexPath); if(indexPath.section == kInvitesReceivedSection){ // delete invite } else if(indexPath.section == kInvitesSentSection){ // delete invite } } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"%s:%d indexPath=%@", __FUNCTION__, __LINE__, indexPath); // Return YES if you want the specified item to be editable. return YES; } #pragma mark UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // do stuff here } </code></pre> <p>EDIT: I actually noticed these logs when I swipe on a cell. However when I swipe on another cell, no logs. This indicates that the delete button is active but not visible to tap. Why?</p> <pre><code>2013-07-10 08:24:57.400 Heartstream[35280:c07] -[SMInvitesViewController tableView:editingStyleForRowAtIndexPath:]:337 indexPath=&lt;NSIndexPath 0xc44b180&gt; 2 indexes [0, 0] 2013-07-10 08:24:57.400 Heartstream[35280:c07] -[SMInvitesViewController tableView:canEditRowAtIndexPath:]:369 indexPath=&lt;NSIndexPath 0xc44b180&gt; 2 indexes [0, 0] 2013-07-10 08:24:57.401 Heartstream[35280:c07] -[SMInvitesViewController tableView:editingStyleForRowAtIndexPath:]:337 indexPath=&lt;NSIndexPath 0xc44b1b0&gt; 2 indexes [0, 0] 2013-07-10 08:24:57.401 Heartstream[35280:c07] -[SMInvitesViewController tableView:canEditRowAtIndexPath:]:369 indexPath=&lt;NSIndexPath 0xc44b1b0&gt; 2 indexes [0, 0] 2013-07-10 08:24:57.401 Heartstream[35280:c07] -[SMInvitesViewController tableView:canEditRowAtIndexPath:]:369 indexPath=&lt;NSIndexPath 0xc44b380&gt; 2 indexes [0, 0] 2013-07-10 08:24:57.401 Heartstream[35280:c07] -[SMInvitesViewController tableView:editingStyleForRowAtIndexPath:]:337 indexPath=&lt;NSIndexPath 0xc44b380&gt; 2 indexes [0, 0] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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