Я хочу получить и сохранить данные из ячейки при событии UILongPressGestureRecognizer. То, что я пытаюсь, заключается в том, что когда пользователь кратковременно зажимает и удерживает его, откроется диалоговое окно (у которого будет 3 или более кнопки), у пользователя будет выбор для сохранения конкретных данных ячейки или для удаления этой ячейки из таблицы или перейти на другой экран.Сохранение данных из ячейки таблицы в UILongPressGestureRecognizer
Ниже приведен код, я использую для этой цели:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILongPressGestureRecognizer *pressRecongnizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tableCellPressed:)];
pressRecongnizer.minimumPressDuration = 0.5f;
[cell addGestureRecognizer:pressRecongnizer];
[pressRecongnizer release];
}
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
cell.textLabel.text =
[self.filteredListItems objectAtIndex:indexPath.row];
}
else{
cell.textLabel.text =
[self.groups objectAtIndex:indexPath.row];
}
return cell;}
- (void)tableCellPressed:(UILongPressGestureRecognizer *)recognizer{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add to Favourites", @"Take to Map", @"Delete" ,nil] ;
[alert show];}
Здесь я хочу знать, как я могу сохранить данные в моей CoreData?
Thanx @Kevin Low –
но одна часть мой вопрос оставлен, что это то, что я могу удалить конкретную ячейку из таблицы, если пользователь удаляет кнопку удаления из диалога –
О, извините! Не заметил. Edited =). –