0

I'm a beginner to making iPhone app with Xcode6. (and excuse me non a native English speaker...)

setting up UITableView with customized cells (as another class, i.e. MyCustomCell)

I would like to show/hide a component (UIView) in customized cell class, when a cell in UITableView has a longpress (longTap) but stacked.

I could not know how to control (recognise) the target component on the same cell in customized cell class with indexPath (or something) some part of programs are as follows,

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;} 
    }
}

Would you please let me know how to go over this trap ?

waka
  • 3,362
  • 9
  • 35
  • 54
  • Ummm..,but still I am in the same trap. How can I specify "a part (=custom panel) in the CustomCell by indexPath.row, which I got now after your suggestions ? I did try this action in the longTapAction but it didn't work well... UITableViewCell *longPressedCell = [self.tableView cellForRowAtIndexPath:indexPath]; longPressedCell.editPanel.hidden = NO; – CapriGino Nov 18 '14 at 20:53

2 Answers2

1

You need to create and assign a gestureRecognizer in to a cell:cellForRowAtIndexPath

UILongPressGestureRecognizer * recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTapAction:)];
    recognizer.delegate = self;
    [cell addGestureRecognizer:recognizer];
LoGoCSE
  • 558
  • 5
  • 13
  • it's OK I added a gestureRecognizer into a cell and could solve my problem, it became simple and clear, thanks LoGoCSE. – CapriGino Nov 18 '14 at 19:16
0

You can add the gesture-recogniser to the UITableView itself and then extract the target UITableViewCell on which the gesture was performed using something like this or this.

Community
  • 1
  • 1
Varun Singh
  • 1,135
  • 13
  • 18
  • Now I did this "adding the gesture-recogniser to the UITableView itself" and could run out from the trap ! thanks Varun Singh ! – CapriGino Nov 18 '14 at 19:15