iphone - UILabel not updating -
sorry basic question, bugs me while now.
i create details view uitable , try dynamically set labels, not updating:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { myobject *tmpobj = [[myobject objectatindex:indexpath.section] objectatindex:indexpath.row]; myviewcontroller *tmpvc = [[myviewcontroller alloc] initwithnibname:@"nibfile" bundle:nil]; [tmpvc.mylabel settext:tmpobj.mytitle]; // debugger shows text: mytitle = "mytext" nslog(@"%@", tmpvc.mylabel); // nslog shows null [self.navigationcontroller pushviewcontroller:tmpvc animated:yes]; [tmpobj release]; }
the connections in interface builder set. connections tab file owner shows
'mylabel' - 'label (mylabel)'
any ideas why value not coming through?
a few more observations:
- i have ibaction connected. method called when click connected button.
- i got few pointers nslog-statement, whether should not better use tmpvc.mylabel.text, trying returns null.
- mylabel declared iboutlet uilabel *mylabel in interface. property defined nonatomic, retain.
there's light:
after playing around bit more moved pushviewcontroller statement above label updates. resolved label updates.
working code looks this:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { myobject *tmpobj = [[myobject objectatindex:indexpath.section] objectatindex:indexpath.row]; myviewcontroller *tmpvc = [[myviewcontroller alloc] initwithnibname:@"nibfile" bundle:nil]; [self.navigationcontroller pushviewcontroller:tmpvc animated:yes]; [tmpvc.mylabel settext:tmpobj.mytitle]; // debugger shows text: mytitle = "mytext" nslog(@"%@", tmpvc.mylabel); // nslog shows null [tmpobj release]; }
but don't understand why need push viewcontroller first ???
that's because controller's view lazily created when accessed. pushing controller accesses view.
alternatively, if add line access view property, work too:
myviewcontroller *tmpvc = [[myviewcontroller alloc] initwithnibname:@"nibfile" bundle:nil]; tmpvc.view; // force view creation [tmpvc.mylabel settext:tmpobj.mytitle]; // debugger shows text: mytitle = "mytext" nslog(@"%@", tmpvc.mylabel); // nslog display "mytext" [self.navigationcontroller pushviewcontroller:tmpvc animated:yes];
Comments
Post a Comment