当我从视图控制器切换到另一个不显示的视图控制器时,我已UILongPressGestureRecognizer
在uimenucontroller
单元格上显示uitableview
。为什么?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = [tableView dequeueReusableCellWithIdentifier:@"CellNotificationTableViewCell" forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[cell addGestureRecognizer:recognizer];
[self longPress:recognizer];
return cell;
}
- (void)longPress:(UILongPressGestureRecognizer *)recognizer {
UITableViewCell *cell2 = (UITableViewCell *)recognizer.view;
if (recognizer.state == UIGestureRecognizerStateBegan) {
// UITableViewCell *cell = (UITableViewCell *)recognizer.view;
UIMenuItem *flag = [[UIMenuItem alloc] initWithTitle:@"Delete" action:@selector(DeleteMsg:)];
UIMenuItem *approve = [[UIMenuItem alloc] initWithTitle:@"Read" action:@selector(ReadMsg:)];
UIMenuItem *deny = [[UIMenuItem alloc] initWithTitle:@"UnRead" action:@selector(UnReadMsg:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObjects:flag, approve, deny, nil]];
[menu setTargetRect:cell2.frame inView:cell2.superview];
[menu setMenuVisible:YES animated:YES];
}
selectedIndexPath = [self.tableView indexPathForCell:cell2];
NSLog(@"%ld",(long)selectedIndexPath.row);
NSUserDefaults *nssave = [NSUserDefaults standardUserDefaults];
[nssave setInteger:selectedIndexPath.row forKey:@"selectedcellrow"];
}
答案 0 :(得分:0)
我不完全确定您的要求,但是当您设置手势识别器时,您将目标设置为自我(即当前视图控制器)。因此,如果您更改视图控制器,则目标不再存在。