I currently have 2 view controllers: ViewController and DetailViewController. Neither of them are Table View Controllers, they are both just View Controllers. However, I do have a table on ViewController which is otherwise working great. I want to segue/pass a variable to DetailViewController when a cell is selected.
Using the storyboard I set up a modal segue from the cell to DetailViewController with the identifier toDetailView.
I tried to use this method to pass my variable (in this example called play) from VC to DVC (via http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Listings/Classes_RootViewController_m.html#//apple_ref/doc/uid/DTS40007416-Classes_RootViewController_m-DontLinkElementID_10):
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"toDetailView"]) {
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.play = [dataController objectInListAtIndex:selectedRowIndex.row];
}
}
However I get an error: Property 'tableView' not found on object type 'ViewController *'. I think this is because it’s not a Table View Controller? How can I get around this? Or is there another method I could use to segue and pass the variable using (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath?
On the ViewController, create a new property like that :
And
synthesizeit. Then, in Interface Builder, you should be able to assign the outlet to the tableview you are using. This should do the trick