OBJECTIVE - C I have a table view which I created programmatically. I have 5 cel
ID: 3811868 • Letter: O
Question
OBJECTIVE - C
I have a table view which I created programmatically. I have 5 cells in that table view. Every time I click a cell I want to go to a specific view controller. I used didSelectRowAtIndexPath and it doesn't work. Here is my code below: How to I click a specific table view cell and go to a specific view controller PROGRAMMATICALLY!
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FirstViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:@"firstView"];
SecondViewController *second = [self.storyboard instantiateViewControllerWithIdentifier:@"secondView"];
ThirdViewController *third = [self.storyboard instantiateViewControllerWithIdentifier:@"thirdView"];
FourthViewController *fourth = [self.storyboard instantiateViewControllerWithIdentifier:@"fourthView"];
FifthViewController *fifth = [self.storyboard instantiateViewControllerWithIdentifier:@"fifthView"];
if (tableView==self.MyTableView)
if (indexPath.row==0) [self presentViewController:first animated:YES completion:nil];
else if (indexPath.row==1) [self presentViewController:second animated:YES completion:nil];
else if (indexPath.row==2) [self presentViewController:third animated:YES completion:nil];
else if (indexPath.row==3) [self presentViewController:fourth animated:YES completion:nil];
else if (indexPath.row==4) [self presentViewController:fifth animated:YES completion:nil];
Explanation / Answer
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.someProperty = [self.someArray objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:@"segueID" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UIViewController *vcToPushTo = segue.destinationViewController;
vcToPushTo.propertyToSet = self.someProperty;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.