我想從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