2015-04-23 120 views
1

我想在我的UITableViewCell中显示信息。我希望能够滑动到单元格的左侧,而不是显示deleteCellButton,我希望看到一段内容。 如何重写此方法来做到这一点。覆盖-tableView:commitEditingStyle:forRowAtIndexPath:显示信息

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 

您的帮助将不胜感激

回答

1

您可以使用下面的委托方法

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return @"Some Content"; 
} 

//普通的委托方法

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Determine if it's in editing mode 
    if (self.tableView.editing) 
    { 
     return UITableViewCellEditingStyleDelete; 
    } 

    return UITableViewCellEditingStyleNone; 
} 

希望它可以帮助你..!

0
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 

     //add code here for when you hit delete 
     NSLog(@"selected row is : %d",indexPath.row); 

      NSString *frndName = [[sections valueForKey:[[[sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 

      NSString *remove = [NSString stringWithFormat:@"Are you sure want to remove '%@' from your friends?",frndName]; 

      UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"" message:remove delegate:self cancelButtonTitle:@"Remove" otherButtonTitles:@"Cancel", nil]; 
      av.title = frndName; 
      [av show]; 


    } 

} 


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"editingStyleForRowAtIndexPath"); 

    return UITableViewCellEditingStyleDelete; 
} 


-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    return @"Remove"; 
} 
0

,如果你想表现出更多的操作可以实现的UITableViewDelegatetableView:editActionsForRowAtIndexPath:方法。 看看UITableViewRowAction课程,看看有什么可能: here