3

I have a viewcontroller with multiple tableviewcells in it. I want move from one of the tableviewcell to another viewcontroller using storyboard. I have a navigation controller for viewcontroller. I didn't really find a way to solve this.

raidfive
  • 6,603
  • 1
  • 35
  • 32
meowsush
  • 187
  • 2
  • 15
  • Do you mean move from a VC to another VC by tap a UITableViewCell ? – Hezron Jan 10 '17 at 06:13
  • Yes when I select cell it should move to a VC – meowsush Jan 10 '17 at 06:15
  • Implement the `didSelectRowAtIndexPath` delegate. When you tap a cell, control will comes into this method. Write the computation logic there and navigate to the respective view controller. – pkc456 Jan 10 '17 at 06:15
  • That the code I want I couldn't use navigationcontroller because its a uitableviewcell – meowsush Jan 10 '17 at 06:17

3 Answers3

1

You should implement didSelectRowAtIndexPath delegate, then some logic for move to another view controller.

@interface ViewController()<UITableViewDelegate>

...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    AnotherViewControllerClass *vc = [[UIStoryboard storyboardWithName:@"StoryboardNameOfAnotherViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"AnotherViewControllerIdentifier"];

    [self.navigationController pushViewController:vc animated:YES];
}
Hezron
  • 352
  • 1
  • 15
  • I couldn't use navigationcontroller " Property 'navigationController' not found on object of type UITableViewCell" – meowsush Jan 10 '17 at 06:30
  • You should implement this in your UITableViewController subclass and not in your UITableViewCell (custom). – Sri Jan 10 '17 at 06:33
  • My Tableview is inside Viewcontroller and I have done inside viewcontroller – meowsush Jan 10 '17 at 06:35
  • then you should implement this inside viewcontroller, not inside uitableviewcell – Hezron Jan 10 '17 at 06:38
  • this function `didSelectRowAtIndexPath` called when you tap a cell, right? and the problem is you couldn't use navigation controller. – Hezron Jan 10 '17 at 07:07
1

if you want to do with storyBoard then you can use Segue to jump from one tableview cell to another ViewController what you have to do is 1). right click and drag from your table view cell to your desired view Controller and then release it you would see a pop up select "show" 2). click the segue and go to identity inspector and name the segue identifier as you wish 3).then you have to just write a method prepareFor segue methodand in that write if statement like this

if (segue.identifier == "your identifier Name")
{
  //`enter code here`write your logic of pushing the viewcontroller  
}

the above code for if is in swift and you can repeat the steps for your all multiple tableviewcell with diffrent identifier name

if not using storyboard then use this method

if (indexpath.row == 0)
{
  //use the push viewcontroller code here 
}

for each index path you can check and push diffrent viewcontrollers

Lucky
  • 41
  • 6
0

Try this..

  • Open Storyboard and select your initial view controller
  • Select editor from top bar menu in your Xcode
  • Select Embed in and choose UINavigationController

And run your code again...