ios - Need assistance setting UIButton in centre using Autolayouts -


i trying programmatically set uibutton vertically , horizontally in centre using autolayouts here code:

- (void)awakefromnib { uiview *av = [[uiview alloc]initwithframe:cgrectmake(0, 0, self.bounds.size.width, 35.0)];  uibutton *donebutton = [[uibutton alloc]initwithframe:cgrectmake(0, 0, 37, 30)];  //uibutton title, color, backgroung color, targer action ...  nslayoutconstraint* cn3 = [nslayoutconstraint constraintwithitem:donebutton                                                           attribute:nslayoutattributecenterx                                                           relatedby:nslayoutrelationequal                                                              toitem:av                                                           attribute:nslayoutattributecenterx                                                          multiplier:1.0                                                            constant:0];     [av addconstraint:cn3];      nslayoutconstraint* cn4 = [nslayoutconstraint constraintwithitem:donebutton                                       attribute:nslayoutattributecentery                                       relatedby:nslayoutrelationequal                                          toitem:av                                       attribute:nslayoutattributecentery                                      multiplier:1.0                                        constant:0];     [av addconstraint:cn4];  [av addsubview:donebutton];     self.thetextfield.inputaccessoryview = av; } 

the above code working fine except 1 thing, getting warning in console:

the view hierarchy not prepared constraint: nslayoutconstraint:0x7fcfc494efb0 uibutton:0x7fcfc2624420'done'.centerx == uiview:0x7fcfc2624230.centerx

when added view, constraint's items must descendants of view (or view itself). crash if constraint needs resolved before view hierarchy assembled. break on -[uiview(uiconstraintbasedlayout) _viewhierarchyunpreparedforconstraint:] debug.

and getting same warning y.

please tell me going wrong why getting warning?

add donebutton av view before setting constraints.

[av addsubview:donebutton];  [av addconstraint:cn3]; [av addconstraint:cn4]; 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -