1

My apps MainViewController uses a UITableView with custom UITableViewCells from CustomCell. With UIPanGestureRecognizer the user can slide a cell left or right. After the slide, the textLabel.text and slide direction are stored to static NSStrings.

The animation code is CustomCell and works fine.

How could MainViewController know or be notified when CustomCell's recognizer.state == UIGestureRecognizerStateEnded?


CustomCell

static NSString *cellAction = NULL; // textLabel.text

static NSString *slideTo = NULL; // slide direction
-(id)initWithStyle{

    UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];

    [self addGestureRecognizer:recognizer];
}

-(void)handlePan:(UIPanGestureRecognizer *)recognizer{

}

MainViewController

-(void)viewDidLoad{

   actionTable = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

   [self.view addSubview:middleActionTable];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

   CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];

   return cell;
}

After this works I plan on using the 2 static strings from CustomCell to perform a modal segue from MainViewController to AnotherViewController. I only need the 2 strings after the slide action.

Nitin Alabur
  • 5,812
  • 1
  • 34
  • 52
riotejas
  • 155
  • 8
  • You have been on SO for quite long. It'd help everyone if you can use proper formatting for your questions (something similar to the way I have edited). – Nitin Alabur Jan 19 '14 at 00:19

1 Answers1

0

add this code

UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];

[self addGestureRecognizer:recognizer];

right after you create the cell in your MainViewController like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

     CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];

     //more of your existing code here

     UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];

     [self addGestureRecognizer:recognizer];
     return cell;
}

And move your handlePan: method to the MainViewController.

Unless there's a strong reason for you to have the handlePan: method in the cell class, its best to add have it in the MainViewController (if you want to avoid creating/setting a delegate or using blocks)

Nitin Alabur
  • 5,812
  • 1
  • 34
  • 52
  • I've tried this. It's a lot to move over, and will be done as a last result. Plus this doesn't allow the tableview to scroll anymore, why is that? Could you go further into detail of using a delegate or blocks. – riotejas Jan 19 '14 at 00:17
  • there are a lot of great answers for "setting a delegate", "setting a delegate on UITableViewCell". here's an example http://stackoverflow.com/questions/8062572/adding-a-delegate-to-a-custom-uitableviewcell-bad-access-error – Nitin Alabur Jan 19 '14 at 00:23