objective c - UITableView in two identical tab views behaves differently -
i created simple project demonstrate unusual behavior. created of in interface builder without touching code it's easy reproduce.
start page embedded in navigation controller containing 1 button, , when clicking on it, screen directed tab views (with navigation bar on top). there 2 unusual things happening when running program. 1) tab item2's table view underneath navigation bar item1's displayed correctly. vs. can see, although 2 table view placed in exact same position, when programme runs, sec 1 hides search bar because of wrong alignment. 2) when clicking on search bar in tab item1, navigation bar not hidden default behavior (where nav bar hides , search bar shows instead). since nav bar semi translucent, can see 'cancel' button underneath nav bar.(any 1 eye can see bluish tint @ upper right corner of screen shot). means search bar goes right location nav bar doesn't go away. also, note table view not shifted search bar(again, default behavior) when search bar active.
ps: using xcode 6. tried adding constraints tableviewcontrollers, no dice. ideas on this? in advance.
as logixologist suggested, can set navigation controller each tab first controller of tab. if don't want that, can add together next code in viewdidload of sec item view controller.
cgfloat shiftdist = cgrectgetheight(self.navigationcontroller.navigationbar.frame) + cgrectgetheight([uiapplication sharedapplication].statusbarframe); self.tableview.contentinset = uiedgeinsetsmake(shiftdist,0, 0, 0.0f); self.tableview.contentoffset = cgpointmake(0, -shiftdist);
after that, there problem rotation. you'll notice if rotate landscape, search bar doesn't stick under navigation bar. here how prepare it.
- (void)viewwilltransitiontosize:(cgsize)size withtransitioncoordinator:(id <uiviewcontrollertransitioncoordinator>)coordinator ns_available_ios(8_0);{ [super viewwilltransitiontosize:size withtransitioncoordinator:coordinator]; cgfloat heightbeforerotation = cgrectgetheight(self.navigationcontroller.navigationbar.frame) + cgrectgetheight([uiapplication sharedapplication].statusbarframe); cgfloat offsety = self.tableview.contentoffset.y; [coordinator animatealongsidetransition:^(id<uiviewcontrollertransitioncoordinatorcontext> context) { } completion:^(id<uiviewcontrollertransitioncoordinatorcontext> context) { cgfloat heightafterrotation = cgrectgetheight(self.navigationcontroller.navigationbar.frame) + cgrectgetheight([uiapplication sharedapplication].statusbarframe); self.tableview.contentinset = uiedgeinsetsmake(heightafterrotation,0, 0, 0.0f); self.tableview.contentoffset = cgpointmake(0, heightbeforerotation + offsety - heightafterrotation); }]; }
objective-c xcode uitableview debugging uisearchbar
No comments:
Post a Comment