0

I have a use case where essentially I have a image in a customized table view cell. When the user selects the image we want to send them to a Profile page.

Normally, I'd do this by

- (IBAction)userClickedProfilePic:(id)sender {

 ProfileViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Profile"];

 vc.postInfo = self.newsfeedData.newsFeedPosts[indexPath.row];

 [[self navigationController] pushViewController:vc animated:YES];

}

But self != have a storyboard reference in this case since it's a UITableViewCell class. Is there a way to pop or push a new viewController from a tableviewcell action?

Anand Suthar
  • 3,678
  • 2
  • 30
  • 52
Debacle
  • 1,181
  • 1
  • 9
  • 12
  • To be clear, the image is on a customized tableviewcell that has other data. We only want to go to the profile page when the user taps the image, nothing else. – Debacle Nov 07 '14 at 18:09
  • 2
    See: http://stackoverflow.com/questions/20655060/get-button-click-inside-ui-table-view-cell – Andrei Nov 07 '14 at 18:14
  • Thanks Andrei, my issue is I'm I have a viewcontroller class that directs the call to the uitableviewcell class. I need to make the pop happen in the latter class. – Debacle Nov 07 '14 at 18:30
  • You can always store a reference to the cell's UITableViewController within the cell itself and call the your functions from there (ie. self.myTableView.instantiateViewController... etc.) – Glynbeard Nov 07 '14 at 19:18
  • Don't pass a reference to the tablevirw's to the cell. Use delegation instead v – Abizern Nov 07 '14 at 20:00

1 Answers1

0

You have plenty of options. What I usually do is that I will create IBAction in viewcontroller which "contains" tableview with its cells. You can create IBOutlets or IBActions in all parents viewcontrollers through IB in a same way you would do it for cell..you might didn't know that.

But you want to click event on uiimageview which is not so straitforward. You have to do it programatically but it's not that hard just do something like this in cellForRowAtIndexPath and implement actionMethod:

UITapGestureRecognizer *actionMethod = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMethod:)];
[cell.yourImageView addGestureRecognizer:actionMethod];

By the way instead of self.storyboard you can use this in case your storyboard is named Main.storyboard.

[UIStoryboard storyboardWithName:@"Main" bundle:nil]
Viktor Kucera
  • 6,177
  • 4
  • 32
  • 43