ios - Screen doesn't update when I change a UILabel's text -
my environment xcode 6.3, target ios8.3 ipad. i'm learning master-detail view using xcode's template. strange problem appears when try set label's text in detail view:
if put statement changes label's text in p1 position, works.
but if put statement in p2 position, doesn't work.
under both circumstances, detaildescriptionlabel.text changed, p1 statement update screen.(i have checked function configureview() called both times)
can helps me? lot.
below code snippets:
mastercontroller.m:
#import "masterviewcontroller.h" #import "detailviewcontroller.h" @interface masterviewcontroller () @property (copy, nonatomic) nsmutablearray *objects; @end @implementation masterviewcontroller - (void)awakefromnib { [super awakefromnib]; self.clearsselectiononviewwillappear = no; self.preferredcontentsize = cgsizemake(320.0, 600.0); } - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. nsstring *path = [[nsbundle mainbundle] pathforresource:@"presidentlist" oftype:@"plist"]; nsdictionary *presidentinfo = [nsdictionary dictionarywithcontentsoffile:path]; self.objects = [nsmutablearray arraywitharray:[presidentinfo objectforkey:@"presidents"]]; self.detailviewcontroller = (detailviewcontroller *)[[self.splitviewcontroller.viewcontrollers lastobject] topviewcontroller]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - segues - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([[segue identifier] isequaltostring:@"showdetail"]) { detailviewcontroller *controller = (detailviewcontroller *)[[segue destinationviewcontroller] topviewcontroller]; controller.navigationitem.leftbarbuttonitem = self.splitviewcontroller.displaymodebuttonitem; controller.navigationitem.leftitemssupplementbackbutton = yes; //p1 //controller.detailitem = (self.objects[indexpath.row])[@"url"]; } } #pragma mark - table view - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return self.objects.count; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath]; cell.textlabel.text = (self.objects[indexpath.row])[@"name"]; return cell; } - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { //p2 //self.detailviewcontroller.detailitem = (self.objects[indexpath.row])[@"url"]; } @end
detailcontroller.m:
#import "detailviewcontroller.h" @interface detailviewcontroller () @property (strong, nonatomic) uipopovercontroller *masterpopovercontroller; @end @implementation detailviewcontroller #pragma mark - managing detail item - (void)setdetailitem:(id)newdetailitem { if (_detailitem != newdetailitem) { _detailitem = newdetailitem; // update view. [self configureview]; } if (self.masterpopovercontroller != nil) { [self.masterpopovercontroller dismisspopoveranimated:yes]; } } - (void)configureview { // update user interface detail item. if (self.detailitem) { self.detaildescriptionlabel.text = self.detailitem; } } - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. [self configureview]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - split view - (void)splitviewcontroller:(uisplitviewcontroller *)svc willhideviewcontroller:(uiviewcontroller *)aviewcontroller withbarbuttonitem:(uibarbuttonitem *)barbuttonitem forpopovercontroller:(uipopovercontroller *)pc { barbuttonitem.title = nslocalizedstring(@"master", @"master"); [self.navigationitem setleftbarbuttonitem:barbuttonitem animated:yes]; self.masterpopovercontroller = pc; } - (void)splitviewcontroller:(uisplitviewcontroller *)svc willshowviewcontroller:(uiviewcontroller *)aviewcontroller invalidatingbarbuttonitem:(uibarbuttonitem *)barbuttonitem { [self.navigationitem setleftbarbuttonitem:nil animated:yes]; self.masterpopovercontroller = nil; } @end
i guess using segues , that's point of using dedicated function (prepareforsegue
) designated appositely initialize values after view destination view has been anyway created.
unless instantiate , show view in didselectrowatindexpath
there no point in setting such viewcontroller.
Comments
Post a Comment