嗨,我正在與tableview.Now我正面臨着一個問題。在我的tableview中,當我使用長手勢我需要顯示Alert Alert.it工作正常。當我點擊alertin視圖中的buttonindex 0時,我需要執行一些Task.But,因爲我需要indexpath。下面是我的方法執行任務如何在alertview上找到indexpath?
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(messageDeleteOrForword:)];
lpgr.minimumPressDuration = 2.0; //seconds
lpgr.delegate = self;
[self.tableView addGestureRecognizer:lpgr];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[self deleteSpecificMessage];
}
if (buttonIndex==1) {
}
}
-(void)messageDeleteOrForword:(UILongPressGestureRecognizer *)gestureRecognizer
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Delete" message:@"Do you want to delete specific message" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Forword", nil];
[alert show];
}
-(void)deleteSpecificMessage
{
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
}
,但我需要通過一些參數就知道了,我使用下面一行 的indexpath - (空)deleteSpecificMessage:(ID)發送 { } 但如何在alertview中調用和分配參數請幫助我。從didselectrowatindexpath
CGPoint location = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
請發佈一些長手勢代碼。 –
可以請你檢查更新的 – Bittoo