questino about the Edit button

Discussion in 'iOS Programming' started by tranvutuan, Feb 3, 2012.

  1. macrumors member

    Joined:
    Dec 19, 2011
    #1
    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
     
  2. macrumors member

    Joined:
    Feb 2, 2009
    #2
    Have you implemented the method which actually allows editing of your UITableView?
     
  3. thread starter macrumors member

    Joined:
    Dec 19, 2011
    #3
    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];
        }
         
    }
     
  4. macrumors member

    Joined:
    Feb 2, 2009
    #4
    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?
     
  5. thread starter macrumors member

    Joined:
    Dec 19, 2011
    #5
    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.
     

    Attached Files:

  6. macrumors member

    Joined:
    Feb 2, 2009
    #6
    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.
     
  7. thread starter macrumors member

    Joined:
    Dec 19, 2011
    #7
    is the setEditing from system or we have to provide one.
     
  8. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    You need to provide one. Call [super setEditing:edit] and [self.tableView setEditing:edit] It is this second call that you're missing.
     

Share This Page