Data not loading to detail view controller when first row selected
When I launch the app in question I load up a table from an array derived from a plist. In didSelectRowAtIndexPath I assign values from the array to sub views in detail view controller and then push the detail view controller onto the stack, but when running the app, the first time I select any row from the table, data from the array does not appear in my detail view controller's subviews/fields. I then click back to the 开发者_如何学Ctable view, re-select the row and the data then loads in the detail view controller.
In the table view controller didSelectRowAtIndexPath method I do the following where xLabel is the UILabel sub view in the pushed view controller's xib:
self.detailViewController.xLabel.text = [[[xArray objectAtIndex: indexPath.section] objectForKey:@"xDesc"] objectAtIndex:indexPath.row];
What do I need to do to have the data appear the first time a row is selected?
I think this is not working because first time when you select a row your detail view controller is not there in memory stack, so you can not call setText method of a label in previous view controller. Second time its working because its there in memory so you can call set method to its component. What i want to say it that when you are pushing detail view controller in stack just set a string of detail view controller here (this string should be property of detail view controller) and then in detail view controller's viewDidLoad method set the text of your label to this string.
If i understood you correctly, there is no xLabel object the first time around as it will be created when the UIViewController is being "loaded". So, when you try to set the text value, it isnt loaded into the label, as there is no label. Subsequent attempts work as the label is created from the first attempt. Anyways, if you need to share some data with the detail view, store then in a dictionary or some other object rather than just assigning it directly to the view from the current controller.
精彩评论