//长按某一行,执行相应操作
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer //长按响应函数
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
return;
}
CGPoint p = [gestureRecognizer locationInView:roomListTable ];
NSIndexPath *indexPath = [roomListTable indexPathForRowAtPoint:p];//获取响应的长按的indexpath
if (indexPath == nil){
NSLog(@"long press on table view but not on a row");
}
else{
longClickIndex = indexPath.row;
longClickView.hidden = NO;
view.hidden = NO;
NSLog(@"long press on table view at row %ld", indexPath.row);
}
}
如果一个cell中有多个按钮,要点击任何一个按钮
给cell设置tag值,然后添加代理方法实现点击不同的按钮
//UITableView的代理方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
PracticeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PracticeCell" forIndexPath:indexPath];
cell.headLabel.text = initkeys[indexPath.row + 1];
cell.array = keys[indexPath.row + 1];
cell.delegate = self;
cell.tag = indexPath.row + 1001;
return cell;
}
//点击cell的代理方法
- (void)clickCell:(PracticeCell *)cell RowAtIndexPath:(NSInteger)integer {
NSLog(@"++++%ld+++%ld", integer, cell.tag - 1000);
NSArray *array = keys[cell.tag - 1000];
NSDictionary *dic = array[integer];
MenuViewController *controller = [[MenuViewController alloc] init];
controller.titles = dic[@"title"];
controller.target = dic[@"code"];
controller.isGaokao = YES;
[self.navigationController pushViewController:controller animated:YES];
}
网友评论