meowsush
meowsush

Reputation: 197

Move from UITableviewcell to a ViewController and back using storyboard

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.

Upvotes: 3

Views: 598

Answers (3)

Lucky
Lucky

Reputation: 41

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

Upvotes: 1

Hezron
Hezron

Reputation: 352

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

Upvotes: 1

Krishna Datt Shukla
Krishna Datt Shukla

Reputation: 997

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...

Upvotes: 0

Related Questions