开发者

iphone (objective-c) accessory modification error

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;
开发者_StackOverflow社区}

Project File Download: Get it here.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜