2013-12-08 2 views
0

Я нахожусь на iOS 7, имею UITableViewController, с UITableView (связанным источником данных и делегатом) и пытаюсь использовать редактирование. Я использую пользовательский UITableViewCell с прототипом Dynamice в UIStoryboard. Когда я нажимаю на кнопку редактирования (self.editButtonItem), вы видите, что изменение имени завершено, но нет значков отступа (- значок). Прокручивание из ячейки работает, я получаю кнопку удаления.Пользовательский UITableViewCell не отображает отступ во время редактирования

Вот мой код:

self.navigationItem.leftBarButtonItem = self.editButtonItem; 

// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 

// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source 
     [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
    } 
} 

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

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 

Все мое содержание находится в contentView

+0

Убедитесь, что пользовательский контент вашей ячейки был добавлен в контент contentView, а не непосредственно в ячейку. – rmaddy

+0

Я добавил свой вопрос, посмотрю на картинку. –

+0

Какой код у вас есть в кнопке редактирования? – rdelmar

ответ

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


    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     [arr removeObjectAtIndex:indexPath.row]; 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom]; 
    } 
} 



- (IBAction)editbtn:(id)sender { 

    if (self.tableView.editing) { 
     self.tableView.editing = NO; 
     [edit setTitle:@"Edit" forState:UIControlStateNormal]; 
    } 
    else{ 
     self.tableView.editing = YES; 
     [edit setTitle:@"Done" forState:UIControlStateNormal]; 
    } 
} 

Я думаю, что этот код поможет вам.

+0

Уже получил! Но это то, что вы можете использовать! –

-2

В виде UIViewController self.editButtonItem не работает, вам нужно создать пользовательскую кнопку.

Смежные вопросы