I have a pretty simple question. Say you have 2 view controllers A and B. A is a UITableView with STATIC CELLS. That is A is built using storyboard objects only as opposed to programmatically. B is also a UITableView but built programmatically with DYNAMIC CELLS. So I wired up Segues (with identifiers set in the storyboard) from each cells in A to the B Tableview.
Now what I would like to have is to know which segue has been pushed when a row in A is selected. I know this can easily be done if I create the cells in view A programmatically and use the prepare/perform segue methods. But since the contents in A will never change, I do not want to go that route. Reason why I am trying to find out how to check which segue has been pushed when I select a given row in A. Ideally there would be some for of a method DIDPERFORMSEGUE: (Segue identifier) I could call from the B Viewcontroller.
Thanks very much for your help and suggestions.
In your "A" TableView, you should be able to peek at which row was poked, and then push that information to your "B" table. For example:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"UITableView_B"]){
BTableViewController *vc = (BTableViewController *)[segue destinationViewController];
NSIndexPath *path;
path = [self.tableView indexPathForSelectedRow];
[vc setSelectedPath:path];
}
}
Hope that helps. Best of luck.
Edit: Probably obvious, but in the above "self.tableView" is an outlet pointing at the UITableView.
Update Personally, I'd bite the bullet and make a class for "A", but in the interest of hacking - it should be possible to reach back and get data from the previous view. This is 'bad code' (imo) and assumes you're using a Navigation Controller - and that the previous view is an "A" table, etc... Without further ado - is should be possible to just do this:
NSArray * views = [self.navigationController viewControllers];
NSUInteger prevViewIndex = [views count] - 2;
UIViewController * previousView = [views objectAtIndex:prevViewIndex];
ATableViewController * aTableViewController = (ATableViewController *) previousView;
NSIndexPath *path = [aTableViewController.tableView indexPathForSelectedRow];