UITableView:如何使用LONG PRESS更改CUSTOM CELL中的UIView状态?

时间:2014-11-17 09:05:25

标签: ios objective-c iphone uitableview

我是使用Xcode6制作iPhone应用程序的初学者。 (原谅我不是母语为英语的人......)

使用自定义单元格设置UITableView(作为另一个类,即MyCustomCell)

我想在自定义单元格类中显示/隐藏组件(UIView),当UITableView中的单元格具有longpress(longTap)但堆叠时。

我不知道如何使用indexPath(或其他)控制(识别)定制单元类中同一单元格上的目标组件,程序的某些部分如下,

MyCustomCell.h

@interface MyCustomCell : UITableViewCell
@property (weak,nonatomic) IBOutlet UIView *customPanel;

UIViewController.m  

#import “MyCustomCell.h"
********************************
- (void)viewDidLoad {
    [super viewDidLoad];
    [_tableView registerNib:[UINib nibWithNibName:@“MyCustomCell" bundle:nil] forCellReuseIdentifier:@"cell"];
}  

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
    {
    MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    return cell;
}

-(void)longtapAction:(UILongPressGestureRecognizer *)gestureRecognizer {

    CGPoint p = [gestureRecognizer locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];

    if (indexPath == nil){
    }else if (gestureRecognizer.state == UIGestureRecognizerStateBegan){

    // I would like to change the hidden status of a UIVIEW in the CustomCell like

                {self.customcell.custompanel:(indexPath).hidden = YES;} 
    }
}

请您告诉我如何查看此陷阱?

2 个答案:

答案 0 :(得分:1)

您需要创建gestureRecognizer并将其分配到单元格:cellForRowAtIndexPath

UILongPressGestureRecognizer * recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTapAction:)];
    recognizer.delegate = self;
    [cell addGestureRecognizer:recognizer];

答案 1 :(得分:0)

您可以将手势识别器添加到UITableView本身,然后使用thisthis等内容提取执行手势的目标UITableViewCell。

相关问题