2014-11-13 4 views
0

Помогите мне пожалуйста. Я пытался удалить ячейку в tableview. Я начинаю разработку iOS.Как удалить ячейку в виде таблицы

, пожалуйста, помогите мне.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    int num = [[self.fetchedResultsController sections] count]; 
    return [[self.fetchedResultsController sections] count]; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

    id sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; 
    NSInteger numberOfRows = [sectionInfo numberOfObjects]; 

    return numberOfRows; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     id cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 
     [self configureCell:cell atIndexPath:indexPath]; 

    return cell; 

} 
- (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 
    } 
} 

способ подключить класс tableviewcell в моей камере, иметь более подробную информацию.

- (void)configureCell:(id)cell atIndexPath:(NSIndexPath *)indexPath 
{ 
    BookDetail *bookDetail = [self.fetchedResultsController objectAtIndexPath:indexPath]; 

    [(storageuser *)cell settingupWithInfo:bookDetail]; 

} 

ответ

0

Вы также должны удалить запись из источника данных с помощью следующей

[self.managedObjectContext deleteObject:bookDetail]; 
[self.managedObjectContext save:nil]; 

[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
1

В tableView:commitEditingStyle:forRowAtIndexPath:, вы должны обновить источник данных (швы быть self.fetchedResultsController) перед вызовом deleteRowsAtIndexPaths:withRowAnimation:

1

Вы должны реализовать метод UITableViewDataSource

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

Таким образом, вся ячейка вашего вида таблицы может быть удалена. Если вы хотите избежать удаления ячейки для определенного пути индексов, просто поставьте условие внутри.

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