Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

UITableView not displaying delete/move icons??

I have a viewcontroller that implements the UITableViewDelegate


@interface SettingsViewController : UIViewController <UITableViewDelegate> {

IBOutlet UITableView *settingsTableView;


I implement the methods that should show the delete/move icon buttons in the table but they won't show up. Can't figure out why??


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.title = @"Settings";
self.tabBarItem.image = [UIImage imageNamed:@"Gears.png"];
UINavigationItem *navigationItem = self.navigationItem;
navigationItem.title = @"Name Settings";

self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
return self;
}



- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSDictionary *currentName =[[[boyNameChoices objectAtIndex:fromIndexPath.row] retain] autorelease];
[boyNameChoices removeObjectAtIndex:fromIndexPath.row];
[boyNameChoices insertObject:currentName atIndex:toIndexPath.row];
}


I can swipe left to right and get the red delete button on the right but not the circle and most importantly not the move icon on the right of the cell.

iMac 24" 2.8g, iPhone 16g Black, 2.1, iPod Touch 16g, Mac OS X (10.5.5)

Posted on Oct 13, 2008 8:12 PM

Reply
10 replies

Oct 13, 2008 8:54 PM in response to gpmoore

You have to put the table in edit mode for all of the delete buttons and reorder icons to show up in the table. The swipe only works for the one row you do the swipe in.

A typical way to do this is to add the view controller's edit button to the navigation bar. Look at the UIViewController docs. There is a property for getting the built in edit button.

Oct 13, 2008 9:12 PM in response to gpmoore

Oops - I overlooked that. I just remembered the other half of what is needed. Since your view controller is a UIViewController and not a UITableViewController you need more plumbing to make the Edit/Done button work. The Edit/Done button is going to call your view controller's setEditing method, not the table's.

You need to override the 'setEditing:(BOOL)editing' method in your view controller like this:


- (void)setEditing:(BOOL)editing {
[self setEditing:editing];
[settingsTableView setEditing:editing];
}


I also prefer to make configuration changes like adding the Edit button in the view controller's 'viewDidLoad' method instead of the 'init' method. It's safer because you know the nib is fully loaded and all your outlet's are setup.

Of course the other option is to extend UITableViewController and let it do 90% of the work for you.

Oct 14, 2008 5:19 PM in response to RickMaddy

RickMaddy -- THANK YOU!!! You saved my A#)*# You don't even want to know how many hours I have fiddled with this trying to get it to work! I did have to make a slight change b/c your code created an endless loop. See the corrected solution below. Thank you again!


- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
//[self setEditing:editing animated:animated];
[settingsTableView setEditing:editing animated:animated];
}

Oct 14, 2008 6:26 PM in response to gpmoore

Ok, I spoke to soon... With the code above the "Edit" button puts the table into edit mode but does not change the text to "Done" and there is no way to exit the editing mode. Here is the correct code in case anyone else has this problem:


- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[settingsTableView setEditing:editing animated:animated];
}

UITableView not displaying delete/move icons??

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.