Я создал приложение на основе контроллера навигации, которое использует основные данные.Не изменяя сначала большую часть кода из запускаемого приложения, я хотел бы иметь возможность добавлять строки, имея возможность добавлять строки через динамическую строку после нажатия кнопки edit.
Другие примеры, которые я нашелнапример, тот, который найден на на этом сайте , демонстрирует желаемую функциональность, однако не использует основные данные, поэтому я не смог правильно перевести это с использованием основных данных.
У меня естьвзглянул на пример приложения iPhoneCoreDataRecipes, и это приложение включает в себя желаемую функциональность, однако пример невероятно сложный.Основываясь на примере приложения, я добавил следующее в мой - (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath function
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// For the Ingredients section, if necessary create a new cell and configure it with an additional label for the amount. Give the cell a different identifier from that used for cells in other sections so that it can be dequeued separately.
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:0];
NSInteger rows = [sectionInfo numberOfObjects];
NSUInteger ingredientCount = rows;
NSInteger row = indexPath.row;
if (indexPath.row < ingredientCount) {
// If the row is within the range of the number of ingredients for the current recipe, then configure the cell to show the ingredient name and amount.
static NSString *IngredientsCellIdentifier = @"IngredientsCell";
cell = [tableView dequeueReusableCellWithIdentifier:IngredientsCellIdentifier];
if (cell == nil) {
// Create a cell to display an ingredient.
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:IngredientsCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
}
//
[self configureCell:cell atIndexPath:indexPath];
} else {
// If the row is outside the range, it's the row that was added to allow insertion (see tableView:numberOfRowsInSection:) so give it an appropriate label.
NSLog(@"---- IN ADD INGREDIENTS SECTION ----");
static NSString *AddIngredientCellIdentifier = @"AddIngredientCell";
cell = [tableView dequeueReusableCellWithIdentifier:AddIngredientCellIdentifier];
if (cell == nil) {
// Create a cell to display "Add Ingredient".
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AddIngredientCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = @"Add Ingredient";
}
return cell;
}
Когда я нажимаю кнопку редактирования, ямогу удалить строки, однако я не получаю добавленную строку, чтобы щелкнуть, чтобы добавить строки.Пример приложения очень сложный, чтобы сказать, чего мне не хватает.Есть ли функция добавления для автоматического добавления кнопки «добавить строку» в конец таблицы?
РЕДАКТИРОВАТЬ: Добавлен весь мой файл .M для справки @ http://pastebin.com/Ld7kVts7 Когда я запускаю шоу NSLog 1-12 в консоли.В настоящее время я не пытаюсь добавить строку «добавить строку» к основным данным, поскольку эта строка добавляется или удаляется каждый раз, когда пользователь нажимает кнопку редактирования на панели навигации.