Jay
Jay

Reputation: 912

tableview selecting new views

Here is the code I have at present:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
[self.navigationController pushViewController:detail animated:YES];

detail.rowNum.text = [NSString stringWithFormat:@"Image %d", (indexPath.row + 1)];

}

which loads the same view controller for every cell on my table view. how do i state that i only want this to happen when one particular row is selected? so for instance i would make the above apply only to row one with another instance for each extra row? alternatively, can this much be done in the storyboard section of Xcode?

UPDATE: following an answer I've updated the code to this which works fine, so i guess it's fine to use if without else?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
if (indexPath.row == 0) {
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
[self.navigationController pushViewController:detail animated:YES];

detail.rowNum.text = [NSString stringWithFormat:@"Image %d", (indexPath.row + 1)];
}

if (indexPath.row == 1) {
    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Forum"];
    [self.navigationController pushViewController:detail animated:YES];

}

}

Upvotes: 0

Views: 186

Answers (1)

agilityvision
agilityvision

Reputation: 7931

Check if indexPath.row == to the row you want. You could only do it in storyboard if your table was static.

Upvotes: 1

Related Questions