views:

123

answers:

1

hi guys I have one last problem that is killing me. I am playing around with an older project which used the tableView:accessoryTypeForRowWithIndexPath method, of which i am trying to rewrite the app without it.

I have deleted the tableView:accessoryTypeForRowWithIndexPath method, but my solution isnt working just yet.

The problem is that now when I press the 'Edit' button on my DetailViewController View, the 'editing' accessory types dont show.

Below is my actual code, and I have also included the project file for this, because I am desperate for a solution that works.

My question is, what code do I have to change, to get the accessory to change, and no other effects. (I know the RootViewController works, but how can i get the DetailViewController table to do the same?)

Regards, @norskben

Project File Download: Get it here.

setEditing

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.navigationItem setHidesBackButton:editing animated:animated];

    [tableView reloadData];
}

cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        cell.editingAccessoryType = UITableViewCellAccessoryCheckmark;
    }

    switch(indexPath.section) {
        case 0:
            cell.textLabel.text = coffeeObj.coffeeName;
            break;
        case 1:
            cell.textLabel.text = [NSString stringWithFormat:@"%@", coffeeObj.price];
            break;
    }

    return cell;
}

Project File Download: Get it here.

+1  A: 

In your setEditing:animated: method you are doing two things that you are really not supposed to do. Reloading the table data there makes no sense. And if you have to change the buttons in your tab bar manually then you have not set them up properly. The system takes care of that for you. If you have properly setup an edit button then you don't even manually have to call setEditing:animated: actually.

I think you should review some UITableView sample code.

St3fan
Strangely enough, your little prod in the right direction fixed it all. I was comparing samples and found my DetailViewController was a UIViewController and not a UITableViewController. (Interface builder i linked the view with tableview, (from the initial view) ). I made the change in the code and interface builder then the accessories worked!. The next thing I did was add some code to remove the red side icons for no row deletion, and the final bit of the puzzle was the addition of self.tableView.allowsSelectionDuringEditing = YES; //de-added in viewDidLoad. Thank you so much.
norskben