我想从UILongPressGestureRecognizer事件的单元格中获取和保存数据。我正在尝试的是,当用户点击并保持很长时间时,将会打开一个对话框(其中将有3个或更多按钮),用户可以选择保存特定的单元格数据,或者从表格中删除该单元格或去另一个屏幕。在UILongPressGestureRecognizer中保存来自tableview单元格的数据
下面是代码我使用这个目的:
-(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?
感谢名单@Kevin低 – 2012-01-12 08:01:25
但一部分我的问题是剩下的,那就是如何从表格中删除特定的单元格,如果用户点击对话框中的删除按钮 – 2012-01-12 08:07:42
哦,对不起!没有注意到。编辑=)。 – 2012-01-12 08:34:22