Reputation: 207
Usually that really sounds like an sbolutely simple task: I have a view and I want to reload its data after it was changes in another view. But: It is not a UITableView
and I didn't use InterfaceBuilde
, the view is created programmatically. The values that are displayed in the TextFields are held in a NSDictionary
. In the other view, the key for the value to be displayed is changed, so I'd like to view the new value if the view is back again. So, here is my code:
- (void)loadView
{
...
NSMutableDictionary *selection = [[ValueDispatcher dispatcher] selectionIndex];
NSDictionary *labels = [[ValueDispatcher dispatcher] labelDic];
NSDictionary *values = [[ValueDispatcher dispatcher] valDic];
NSEnumerator *theKeys = [labels keyEnumerator];
while (key = [theKeys nextObject])
{
CGRect frame = CGRectMake(10, i, 300, 30 );
UILabel *label = [[UILabel alloc] initWithFrame:frame];
[label setText:[labels objectForKey:key]];
[[self view] addSubview:label];
CGRect fieldFrame = CGRectMake(10, i + 40, 300, 30 );
textField = [[UITextField alloc] initWithFrame:fieldFrame];
[textField setText:[[values objectForKey:key] objectForKey:[selection objectForKey:key]]];
[[self view] addSubview:textField];
}
....
when my view is back the old values ist still displayes and nothing changed. Which method should I use? I already tried reloadInputViews but it didn't work, other methods I know only (reloadData) only work for a TableView...
Upvotes: 0
Views: 1231
Reputation: 27597
In case that view is hidden/pushed/off-screen while changing the values and becomes visible afterwards through e.g. popping from the navigation stack, you may consider using viewWillAppear:animated:
for updating your fields. In any case, you should decouple the updating and the view creation.
That is, in loadView, just create those views and in another method (e.g. updateData), update their displayed data. For holding a reference to those subviews, you could either use tags or proper instance variables within your viewController.
Within the loadView you could manually invoke updateData
as well as in viewWillAppear:animated:
.
Upvotes: 2