uitableview - UICollectionView Data Source methods inside of UITabBarView not being called until tab is navigated to -
i have issue can reproduce. can see issue life of me cant figure out how correct it. first, let me explain view structure.
the root view controller window tabbarcontroller. tabbarcontroller contains 2 views, navigationcontroller 1 (nav) root view contrller set uitableview , navigationcontroller 2(nav2) root view controller set uicollectionview. here how setup in appdelegate:
wtatableview *tv = [[wtatableview alloc] initwithnibname:@"wtatableview" bundle:nil]; uinavigationcontroller *nav = [[uinavigationcontroller alloc] initwithrootviewcontroller:tv]; nav.tabbaritem.title = nslocalizedstring(@"birthday list", nil); nav.tabbaritem.image = [uiimage imagenamed:@"birthdaycake"]; wtacollectionviewcontroller *cv = [[wtacollectionviewcontroller alloc] initwithcollectionviewlayout:[[uicollectionviewflowlayout alloc] init]]; uinavigationcontroller *nav2 = [[uinavigationcontroller alloc] initwithrootviewcontroller:cv]; nav2.tabbaritem.title = nslocalizedstring(@"birthday grid", nil); nav2.tabbaritem.image = [uiimage imagenamed:@"package"]; uitabbarcontroller *tabcontroller = [[uitabbarcontroller alloc] init]; tabcontroller.viewcontrollers = @[nav, nav2]; self.window.rootviewcontroller = tabcontroller; [self.window makekeyandvisible]; return yes;
the collectionview subscribes notification posted entry view controller , takes data returned in notification userinfo dictionary , updates uicollectionview calling data source methods. here code:
-(void)handlenotification:(nsnotification *)notification { [self.birthdays addobject:[notification userinfo]]; nslog(@"calling handle method"); if([self.birthdays count] == 1){ [self.collectionview reloaddata]; } if (self.birthdays.count > 1) { nslog(@" number of itmes in section b: %d", [self.collectionview numberofitemsinsection:0]); [self.collectionview insertitemsatindexpaths:@[[nsindexpath indexpathforitem: (self.birthdays.count -1) insection:0]]]; } }
so on first tab bar item contains nav root controller set uitableview, if tap navbarbutton show modal view controller , user entry , dismiss modal controller return uitableview, new table entry. if tap on tab bar item contains nav2 root controller uicollectionview , uitable tab bar item, can continue add many entries want, no problems. but, if dont navigate tab bar item containing uicollectionview , try add second entry uitableview, crash every single time, invalid number of items in section".
i can see if dont navigate uicontroller tab, data source methods uicontroller never called. uicollectionview not being initialized until navigate tab bar know because nslog out init methods , view did load methods when app first starts up. thought might have uicollectionview being wrapped in nav2 controller took away , ge exact same behavior... feel missing here causing me lot of grief... suggestions appreciated.
i figured out how work. feels "hacky" works :-) had simulate tab bar navigation event in code. in handler method outlined above, in condition birthdays == 1 added self.tabbarcontroller.selectedindex = 1; then, in cellforitematindexpath method, before returning cell, inserted self.tabbarcontroller.selectedindex = 0; still wish knew root cause, flipping , uicollectionview tabb ar does.....
Comments
Post a Comment