How to pass data to child UINavigationController?
On the first view. I have a UItable. When i tap one of the cell(eg chicken), it will go to child(subview) and display the de开发者_如何学运维tails(chicken color).
Any good advise or tutorial how to do this?
Thank you very much.
Get a good book.
Basically, you push a new View Controller using
[someNavigationController pushViewController:someVC animated:YES]
You call this from the UITableViewDelegate
method called
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This method gets called whenever the user taps a cell in a UITableView
.
To pass data, you either use a custom init method, for instance
-(id)initWithChicken:(ChickenObject *)chicken
or you use an instance variable and set it like so
[someVC setChicken:someChicken]
Agree with fabian789 for passing the values to the second view. In theory there is a third way, setting the first view to be the delegate of the second view. In this way, you can always call the delegate methods in second view and get what you need from the first view. Usually I use custom -init or access the second view's property directly. And then I set the first view controller to be the delegate of the second one and then I can pass the value back. Hope this helps.
精彩评论