Discussion Forums  >  Config Data, JSON, App Refresh

Replies: 3    Views: 129

chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
12/17/12 01:08 PM (11 years ago)

switching tabs in code

I posted this in another thread, but it was starting to get off-topic, so I thought I'd create a new topic. I'm using Kittsy's method for swiping in iOS to switch from one tab to another. I'm able to load a different screen no problem. But I'm having problems getting the tabbar to display properly. Any ideas why this might be? Here's my code: - (IBAction)rightSwipe:(id)sender { [BT_debugger showIt:self:@"right swipe activated"]; //appDelegate myAppName_appDelegate *appDelegate = (myAppName_appDelegate *)[[UIApplication sharedApplication] delegate]; //get total number of tabs int tabCt = 0; int tabCount = [[NSNumber numberWithInteger:[appDelegate.rootApp.tabs count]] intValue]; BT_item *thisScreen = nil; thisScreen = self.screenData; NSString *thisScreenID = thisScreen.itemId; while (tabCt < tabCount){ BT_item *screenObjectToLoad = nil; screenObjectToLoad = [appDelegate.rootApp.tabs objectAtIndex:tabCt]; NSString *lastTabPointsTo = [BT_strings getJsonPropertyValue:screenObjectToLoad.jsonVars:@"homeScreenItemId":@""]; [BT_debugger showIt:self:@"checking IDs"]; [BT_debugger showIt:self:thisScreenID]; [BT_debugger showIt:self:lastTabPointsTo]; //if current tab == indexed tab if ([thisScreenID isEqualToString:lastTabPointsTo]) { int loadCt = 0; if (tabCt == 0) {loadCt = tabCount - 1;[BT_debugger showIt:self:@"selecting last tab"];} else {loadCt = tabCt - 1;[BT_debugger showIt:self:@"selecting next tab"];} [BT_debugger showIt:self:@"found a match!"]; screenObjectToLoad = [appDelegate.rootApp.tabs objectAtIndex:loadCt]; NSString *getTabID = [BT_strings getJsonPropertyValue:screenObjectToLoad.jsonVars:@"homeScreenItemId":@""]; screenObjectToLoad = [appDelegate.rootApp getScreenDataByItemId:getTabID]; if(screenObjectToLoad != nil){ [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:screenObjectToLoad:screenObjectToLoad]; }else{ //show message [BT_debugger showIt:self:[NSString stringWithFormat:@"%@",NSLocalizedString(@"menuTapError",@"The application doesn't know how to handle this click?")]]; } } tabCt ++; }; }
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/17/12 01:35 PM (11 years ago)
I was looking at this earlier, sorry but I'm not too familiar with the tab bar code.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/17/12 01:52 PM (11 years ago)
No problem - I figured this might open it up to a broader audience for feedback.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
01/08/13 12:10 PM (11 years ago)
just to follow up - figured out the code. It was remarkably simple: - (void)leftSwipe:(id)sender { NSLog(@"left swiped"); BT_appDelegate *appDelegate = (BT_appDelegate *)[[UIApplication sharedApplication] delegate]; int lastTab = [appDelegate.rootApp.tabs count]; UITabBarController *tabBarController= self.tabBarController; int currentTab = tabBarController.selectedIndex; if (currentTab == lastTab) tabBarController.selectedIndex = 0; else tabBarController.selectedIndex = tabBarController.selectedIndex+1; } - (void)rightSwipe:(id)sender { NSLog(@"right swiped"); BT_appDelegate *appDelegate = (BT_appDelegate *)[[UIApplication sharedApplication] delegate]; int lastTab = [appDelegate.rootApp.tabs count]; UITabBarController *tabBarController= self.tabBarController; int currentTab = tabBarController.selectedIndex; if (currentTab == 0) tabBarController.selectedIndex = lastTab-1; else tabBarController.selectedIndex = tabBarController.selectedIndex-1; }
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.