2015-04-23 112 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