ios - tableHeaderView UISearchBar not showing -
i have added uisearchbar programatically uitableview, showing fine untill decided add offset uitableview hide uisearchbar when view loaded. displaying again.
this code looks like.
- (void)viewdidload { [super viewdidload]; self.tableview.contentoffset = cgpointmake(0.0f, 44.0f); mysearchbar = [[uisearchbar alloc] initwithframe:cgrectmake(0.0f, 0.0f, 320.0f, 44.0f)]; mysearchbar.autocorrectiontype = uitextautocorrectiontypeno; mysearchbar.autocapitalizationtype = uitextautocapitalizationtypenone; mysearchbar.keyboardtype = uikeyboardtypealphabet; mysearchbar.delegate = self; self.tableview.tableheaderview = mysearchbar; // create search display controller uisearchdisplaycontroller *searchcontroller = [[uisearchdisplaycontroller alloc] initwithsearchbar:mysearchbar contentscontroller:self]; searchcontroller.searchresultsdatasource = self; searchcontroller.searchresultsdelegate = self;
i not sure go here appreciated.
this code work in both ios6 , ios7. note in ios7 loose transparency of navigationbar
if ([self respondstoselector:@selector(edgesforextendedlayout)]) { self.edgesforextendedlayout = uirectedgenone; } [self.tableview setcontentoffset:cgpointmake(0, mysearchbar.frame.size.height)];
if want save default transparency in ios7 use code:
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; if ([self respondstoselector:@selector(edgesforextendedlayout)]) { [self.tableview setcontentoffset:cgpointmake(0, -20)]; } else { [self.tableview setcontentoffset:cgpointmake(0, mysearchbar.frame.size.height)]; } }
Comments
Post a Comment