0

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; 

Update

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.

6
  • why are you using detailTextLabel twice? optionTable.cell1.detailTextLabel.detailTextLabel.text = child.selectedMetal; Commented May 28, 2015 at 19:38
  • typo. I'll edit it. thanks Commented May 28, 2015 at 19:51
  • You're not 'referencing" the container's table view with, OptionTableViewController *optionTable = [[OptionTableViewController alloc] initWithNibName:@"OptionTableViewController bundle:nil];, you're creating a new instance of it. Commented May 28, 2015 at 20:08
  • Ok, so is there a way to make sure that cell1 displays it's "optionTable" value? Commented May 28, 2015 at 20:50
  • Or maybe a better way to say it is how do I make sure that the cell displays the value specified for the new instance of *optionTable? Commented May 29, 2015 at 19:23

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.