Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
692 views
in Technique[技术] by (71.8m points)

ios - UITableView delete button not appearing

When I press the edit button I get the round delete icon to the left of the item. When I press the delete icon in the cell it 'turns' but the delete button does not show up so my commitEditingStyle never gets called because I have no delete button to press.

Just for fun...I change the cell to Insert I get the plus icon...I press it and commitEditingStyle is called.

I do not understand why I am not getting the delete button.

I have a UIViewController that I am showing in a popover. I am adding a UITableView to like so...

audioTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 303)];
audioTable.delegate = self;
audioTable.dataSource = self;
[self.view addSubview:audioTable];

I am using a custom cell with two labels in it to display text.

Here is the custom cell initWithFrame...

primaryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25 ,8, 275, 25)];
primaryLabel.font = [UIFont systemFontOfSize:14];

secondaryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25 ,28, 275, 25)];
secondaryLabel.font = [UIFont systemFontOfSize:12];

[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:secondaryLabel];

[self.contentView sendSubviewToBack:primaryLabel];
[self.contentView sendSubviewToBack:secondaryLabel];

I have a delete button in a toolbar in the view controller that is hooked up to the edit call. Here is what I am doing in the edit call which is getting called fine because I am getting the delete symbol in the cell...

if([self.audioTable isEditing]) {
    [button setTitle:@"Edit"];
    [super setEditing:NO animated:NO];
    [self.audioTable setEditing:NO animated:YES];
} else {
    [button setTitle:@"Done"];
    [super setEditing:YES animated:NO];
    [self.audioTable setEditing:YES animated:YES];
}

I have implemented the following...

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
     return UITableViewCellEditingStyleDelete;
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    //i don't think i need to implement this really
    return YES;
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //do delete stuff
    }
}

Like I said everything is working normally, button presses and all work...just no delete button.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had to work around it by using a different mechanism. I did a test and when I used a UITableViewController it worked fine. When I added a UITableView to a UIViewController, implementing the same thing as the UITableViewController does, it does not work. I do not know what I missed, but using the UIViewController as opposed to the UITableViewController caused the delete button to not appear.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...