ios - Why changing xib's constraint is invalid in url request's success block? -


i have written viewcontroller using interface building: top part tableview, bottom part uiview(called bottomview).the tableview's bottom bottomview's top, , add height constraint in bottomview control height of tableview.then link bottomview's height constraint viewcontroller's property. let's see xib picture viewcontroller. viewcontroller's xib 

the constraints in viewcontroller in picture followed(the first picture tableview's, second bottombackview's):

enter image description here  enter image description here in viewcontroller, use iboutlet corresponding link this:
@property (strong, nonatomic) iboutlet nslayoutconstraint *bottomviewheightconstraint;
change bottomviewheightconstraint's constant in url request's success block this:

[getcontacts startwithparams:@{@"bizid":self.bizid, @"bizcode":@(self.bizcode)} success:^(id responseobject) { self.bottomviewheightconstraint.constant = self.bottomcontentview.height; [self.view setneedslayout]; } 

first time, value of self.bottomviewheightconstraint.constant 70 here, , result right. second time value 0, expected result this(table view can scrolled screen bottom):enter image description here
result this(the tableview can't scrolled screen bottom):enter image description here

according comment,i used gcd this:

        dispatch_queue_t mainqueue = dispatch_get_main_queue();     dispatch_async(mainqueue, ^{         self.bottomcontentview.frame = cgrectmake(0.0f, 0.0f, screenwidth, 0.0f);         [self.bottomcontentview configviewwithmodel:model];         self.bottomviewheightconstraint.constant = self.bottomcontentview.height;         [self.view setneedslayout];         [self.view layoutifneeded];     }); 

it doesn't work too. there 1 point troubled me too:when change constraint's constant in method invoked in method 'viewdidload', doesn't work if don't call method 'layoutifneeded' code(i think call method 'setneedslayout' enough):

- (void)viewdidload {     [super viewdidload];      [self addbottomview]; } - (void)addbottomview {     self.bottomcontentview.delegate = self;     self.bottomcontentview.frame = cgrectmake(0.0f, 0.0f, screenwidth, 0.0f);     self.bottomviewheightconstraint.constant = 0.0f;     [self.view setneedslayout];     [self.view layoutifneeded];     [self.bottombackview addsubview:self.bottomcontentview]; } 


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -