2013-11-22 5 views
1

Я могу поместить UITableView в режим редактирования и показать кнопку удаления. Как добавить синюю кнопку «Изменить» рядом с кнопкой удаления?Кнопка редактирования и удаления UITableView

Так же, как прокрутка влево по почте в ios6, за исключением того, что приложение для почты показывает «Больше», я хочу кнопку «Изменить».

+0

'UITableViewCell' не делает поддерживают такую ​​функцию. Вам нужно катиться самостоятельно. См. Https://github.com/CEWendel/SWTableViewCell – rmaddy

+0

Хорошо, спасибо за ссылку. – user2228755

ответ

1

Это не функция, которая поставляется с стандартом Apple UITableViewCell - вам понадобится создать собственный подкласс UITableViewCell с помощью собственного распознавателя проводов.

This GitHub project отличный старт - используя его, вы должны быть в состоянии использовать этот код:

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

    SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) { 
     NSMutableArray *rightUtilityButtons = [NSMutableArray new]; 

     [rightUtilityButtons sw_addUtilityButtonWithColor: 
        [UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0] 
        title:@"More"]; 
     [rightUtilityButtons sw_addUtilityButtonWithColor: 
        [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f] 
         title:@"Delete"]; 

     cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
        reuseIdentifier:cellIdentifier 
        containingTableView:_tableView // For row height and selection 
        leftUtilityButtons:nil 
        rightUtilityButtons:rightUtilityButtons]; 
     cell.delegate = self; 
    } 
... 

return cell; 

Вы затем реализовать метод делегата для ячейки:

- (void)swippableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index { 
    switch (index) { 
     case 0: 
      NSLog(@"More button was pressed"); 
      break; 
     case 1: 
     { 
      // Delete button was pressed 
      NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell]; 

      [_testArray removeObjectAtIndex:cellIndexPath.row]; 
      [self.tableView deleteRowsAtIndexPaths:@[cellIndexPath] 
        withRowAnimation:UITableViewRowAnimationAutomatic]; 
      break; 
     } 
     default: 
      break; 
    } 
} 
Смежные вопросы