Я использую шаблон приложения XCode Navigation-based для создания приложения, основанного на UITableView. У меня возникли проблемы с удалением некоторых строк в tableView.
Во всех ячейках tableViews я добавил кнопку, создав подкласс UITableViewCell следующим образом:
TableViewCell.h:
@implementation TableViewCell
@synthesize button;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
RoutinesAppDelegate *appDelegate = (RoutinesAppDelegate *) [[UIApplication sharedApplication]delegate];
// Initialization code
button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setFrame:CGRectMake(320.0 - 90.0, 6.0, 80.0, 30.0)];
[button setTitle:@"Done" forState:UIControlStateNormal];
[button addTarget:appDelegate action:@selector(routineDone) forControlEvents:UIControlEventTouchUpInside];
button.hidden = YES;
[self.contentView addSubview:button];
}
return self;
}
при нажатии кнопки вызывается метод «рутина» в RoutinesAppDelegate.m.
Метод выглядит так:
RoutinesAppDelegate.m
-(void) routineDone
{
if ([[NSFileManager defaultManager] fileExistsAtPath:[self todayListPath]])
{
int indexToRemove = buttonIndex + 1;
todayListArray = [NSMutableArray arrayWithContentsOfFile:[self todayListPath]];
[todayListArray removeObjectAtIndex:indexToRemove];
[todayListArray writeToFile:[self todayListPath] atomically:YES];
}
}
Этот метод удаляет элемент из массива, который загружает tableView. Это отлично работает.
МОЯ ПРОБЛЕМА:
Ячейка не удаляется с экрана при нажатии кнопки.
В RoutinesAppDelegate.m я пытался использовать
[tableView reloadData]
но, похоже, он не работает извне класса RootViewController.
Было бы неплохо, если бы я каким-то образом мог использовать метод deleteRowsAtIndexPaths, но я не знаю, как вызвать этот метод извне commitEditingStyle в классе RootViewController.
Так что мой вопрос действительно: как заставить клетку уйти? :)