Reputation: 1
I'm trying to make a very basic settings app where a user sets 5 options on a UIViewController and then performs a function based on the selected options. 3 of the options are in a container which contains a UITableView. When a cell from the table view is selected, a new view controller is shown with options for that cell (i.e. user selects "Metal" from the table, and then "Steel" from a new detail view controller). When a value is selected, the UIViewContoller/parent view is shown using an unwind segue and the detail text for the "Metal" row should display "Steel" in the container table
The cell selection segue works appropriately, and NSLog shows that the option selected is being stored correctly. The issue is that I can't figure out how to set the detail text label to the newly set variable. What code do I need to set detail text labels on the container table from the UIViewController?
A little additional info: my unwind segue goes back two view controllers. If I unwind to the table inside the container, the segue doesn't work on row selection.
Here's the prepareForSegue code from settings selection (the view controller that shows "Steel" from my example)
//Sets selected metal on row selection
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender: (UITableViewCell *)sender {
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:selectedIndexPath];
self.selectedMetal = cell.textlabel.text;
NSLog (@"%@", self.selectedMetal);
}
This is the code for my unwind segue and is executed once a detail row is selected:
-(IBAction) unwindToParentView:(UIStoryBoardSegue *)segue{
MetalTableViewController *child = (MetalTableViewController *) segue.sourceViewController;
//Trying to reference the container table here
OptionTableViewController *optionTable = [[OptionTableViewController alloc] initWithNibName:@"OptionTableViewController bundle:nil];
//Have a table view cell in the .h set as an IBOutlet that I'm trying to set here
optionTable.cell1.detailTextLabel.text = child.selectedMetal;
The issue definitely has something to do with the new instance of OptionTableViewController that I'm creating. I can manually set the value of the the detailTextLabel for my container table view controller in its viewDidLoad method, but when I try to NSLog the value for optionTable.detailTextLabel.text it returns a (null) value which means I've got something wonky in my unwind block or I'm not passing the selectedMetal variable correctly.
Upvotes: 0
Views: 208
Reputation: 1
To fix this issue, I changed my initial design a little and put all of my options in a table view controller. Now my segues work correctly and I'm not having any issues passing data between controllers. If anyone can propose a solution for the original issue (passing data from a parent view to it's embedded container view), I'll gladly give it a try and upvote the answer if it works.
Upvotes: 0