I am working on an Iphone application using storyBoard.
I have a UITableView in a UINavidationView. where I load data in custom cells. and then I when the user clicks on a cell I go to another view (ResultView).
I set up the views and the segue in the storyboard.
My goal is to pass data to the ResultView from the prepareForSegue method.
For that I have created a custom cell that implements the UITableViewCell. and then I added a property of type NSDate named: creationDate. I need to pass the creation date of the selected cell to the ResultView.
I have the following
ate = readingCell.creationDate;
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"resultViewSegue"])
{
//Get a reference to the destination
ResultsViewController * destinationView = segue.destinationViewController;
//I try to get the selected cell in order to pass it's property
historyCellClass * selectedCell = (historyCellClass*) sender;
//pass the creation date to the destination view (it has its own creation date property)
[destinationView setCreationDate:selectedCell.creationDate];
}
}
However the creation date of the result view is always null.
looks like I am not getting a reference of the selected cell in order to read its property.
How can I pass the date of the cell to the next view?
Thanks a lot for any help
The way I’ve handled this is with a manual triggering of the segue and an ivar representing selection state.
Make sure the segue being triggered goes from one view controller to the next (not from one of the tableView cells).
selectedModel is the new ivar whose type is the same as a single element in the array that supports the table datasource. Look it up with the index path exactly as you would in cellForRowAtIndexPath:.
Now in prepareForSegue:..
There are a few choices for what state to save in between the table view selection and the start of the segue. You can save the selected index path, or the model element as I suggest, or just the aspect of the model you intend to pass forward (the creationDate in your e.g.). The only bad idea for saving state is the table cell itself.