Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tranvutuan

macrumors member
Original poster
Dec 19, 2011
74
0
I am adding a Edit button to the top right corner of tool bar by doing this
Code:
- (void)viewDidLoad
{
    NSLog(@"VIEW DID LOAD");
    [super viewDidLoad];
    // Initialize var

    self.navigationController.navigationBarHidden   = NO;
    self.navigationItem.hidesBackButton                = NO;

    self.navigationItem.rightBarButtonItem            = [self editButtonItem];
}
Also, the documentation indicated that
Code:
Name:editButtonItem - (UIBarButtonItem *)editButtonItem
Availability: iOS (2.0 and later)
Abstract: Returns a bar button item that toggles its title and associated state between Edit and Done.
However, when i run the program and try to click on EDIT button. It is changed to DONE but the each row of my table does not have any red circle with (-) before...

Please guide me on this issue. Thanks
 

phantax

macrumors member
Feb 2, 2009
72
0
Have you implemented the method which actually allows editing of your UITableView?
 

tranvutuan

macrumors member
Original poster
Dec 19, 2011
74
0
Have you implemented the method which actually allows editing of your UITableView?
Yes I did and here it is

Code:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    if (editingStyle == UITableViewCellEditingStyleDelete) {
         NSLog(@"JUST DELETE AN ITEM AT %d",[indexPath row]);
	[myTableView reloadData];
    }
     
}
 

phantax

macrumors member
Feb 2, 2009
72
0
Is your controller acting as a UITableViewController in your header file?

Is this ViewController also your data source?
If so, is it working correctly to load data into the cells as you expect?
 

tranvutuan

macrumors member
Original poster
Dec 19, 2011
74
0
Is your controller acting as a UITableViewController in your header file?

Is this ViewController also your data source?
If so, is it working correctly to load data into the cells as you expect?

What i have is
Code:
@interface myClass : UIViewController <UITableViewDataSource,UITableViewDelegate>
........
........
........
@end
I also attach 2 images from from xib so you can know what I am doing now.
 

Attachments

  • Screen Shot 2012-02-03 at 3.15.16 PM.png
    Screen Shot 2012-02-03 at 3.15.16 PM.png
    43.9 KB · Views: 71
  • Screen Shot 2012-02-03 at 3.15.34 PM.png
    Screen Shot 2012-02-03 at 3.15.34 PM.png
    30.3 KB · Views: 50

phantax

macrumors member
Feb 2, 2009
72
0
Your class is a UIViewController and not a UITableViewController so you are basically expecting to gain some functionality for free.

There are some things that a UITableViewController will do for you automatically, which will not happen in this case, one of which happens to be toggling the edit mode of a TableView.

If you aren't doing anything out of the ordinary, I would recommend you subclass UITableViewController. Otherwise, look into the "setEditing" method for UITableView to do it yourself.
 

tranvutuan

macrumors member
Original poster
Dec 19, 2011
74
0
Your class is a UIViewController and not a UITableViewController so you are basically expecting to gain some functionality for free.

There are some things that a UITableViewController will do for you automatically, which will not happen in this case, one of which happens to be toggling the edit mode of a TableView.

If you aren't doing anything out of the ordinary, I would recommend you subclass UITableViewController. Otherwise, look into the "setEditing" method for UITableView to do it yourself.

is the setEditing from system or we have to provide one.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
You need to provide one. Call [super setEditing:edit] and [self.tableView setEditing:edit] It is this second call that you're missing.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.