pri pri - 4 months ago 7
Objective-C Question

Navigating pages in different tableview

I have created a screen containing two table views where i have successfully called the method cellForRowAtIndexPath but now am facing trouble in navigating to the other page from tableview option by using didSelectRowAtIndexPath.I think am doing some mistake and i have clearly no idea what is the next step.Can anyone guide how should i do it?? I have used this code-

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView isEqual:leftTableView]) {

TattooSinglesScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:@"TattooSinglesScreen"];


EyecatcherScreen *obj1=[self.storyboard instantiateViewControllerWithIdentifier:@"EyecatcherScreen"];


TattooToplist *obj2=[self.storyboard instantiateViewControllerWithIdentifier:@"TattooToplist"];


int i=indexPath.row;

if(i==0){
[self.navigationController pushViewController:obj animated:nil];
}
else if (i==1) {
[self.navigationController pushViewController:obj1 animated:NO];
}
else if (i==2) {
[self.navigationController pushViewController:obj2 animated:NO];
}


}

else {
TattooSinglesScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:@"TattooSinglesScreen"];


EyecatcherScreen *obj1=[self.storyboard instantiateViewControllerWithIdentifier:@"EyecatcherScreen"];


TattooToplist *obj2=[self.storyboard instantiateViewControllerWithIdentifier:@"TattooToplist"];


int i=indexPath.row;

if(i==0){
[self.navigationController pushViewController:obj animated:nil];
}
else if (i==1) {
[self.navigationController pushViewController:obj1 animated:NO];
}
else if (i==2) {
[self.navigationController pushViewController:obj2 animated:NO];
}

}
}

Answer

If you want to navigate from table view to another view controller don't set animated:NO.set animated:YES for navigating.But if you set animated:NO,definitely it does not navigate.So you have to do following things for navigating.

YourViewController *yourVC = (YourViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"StoryBordIdentifier"];
[self.navigationController pushViewController:yourVC animated:YES];

Also You can use in this didSelectRowAtIndexPath

[self performSegueWithIdentifier:@"segueID" sender:self];

with

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  YourViewController *vc = segue.destinationViewController;
}

Click Table Row and Go another Page

Segue or didSelectRowAtIndexPath

Making Push Segue when table row is selected

Comments