Domanda

I'll be really grateful for any help with this - i've been trying to figure out how to change tabs on a tabbarcontroller from within a nested UITABLEVIEW as in RayWenderlich.com's tutorial on a pulse like scroller http://www.raywenderlich.com/4723/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2 but am getting really stuck. I am using storyboards and xcode 4.4

I'm completely new to xcode as of a few weeks so I apologise if this is a newbie question. I have got the nested horizontal tableviews working fine as per the image in the link above but I want to use the images to switch to a new tab but can't - I think this is because the tableview is nested so I can't find the right reference to the tabbarcontroller in the hierarchy.

if I use ArticleListViewController.m didselect where the tutorial included comments seem to suggest to insertion navigation code will generate an NSLog output and change tabs ok but only using a tiny thin strip above the images (I discovered this by accident) but nothing happens with the images.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
   {
      // Navigation logic may go here. Create and push another view controller   

   //THIS SELECTS WHEN CLICK THINSTRIP JUST ABOVE BUTTONS
   NSLog(@"ARTICLELISTVIEWCONTROLLER check didSelect: %u", self.tabBarController.selectedIndex);  

   self.tabBarController.selectedIndex = 2;
       }

the following code within HorizontaTableCell.m more appropriately generates an NSLog output when I click on the actual images but I can't figure out the tabbarcontroller reference that allows me to change tabs.

   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
   {

    //the following line just generates an Error as follows: Property tabBarController not found on object of type 'HorizontalTableCell *'  

   self.tabBarController.selectedIndex = 2;

   NSLog(@"HORIZONTALTABLECELL DIDSELECT");

   }

Ive looked and looked for a way round this but can't figure it out. Found a mention of using appdelegate but not sure how to do this. can't post storyboard image as new user but has a tabbarcontroller with 4 navigation controllers coming out - the first is the ArticleListViewController menu and each of the others are viewcontrollers - one I hope to put a webview that loads a link/local page depending on the menu selected and the others for an about screen and an additional currently blank screen.

Please help!

thanks!

È stato utile?

Soluzione

I'm guessing you have the tabBarController as a property in your app delegate?

You can reach your app delegate with: [[UIApplication sharedApplication] delegate]

Cast that to your app delegate class and the compiler will not warn you for reaching at the tab bar controller. Like this:

((YourAppDelegate *) [[UIApplication sharedApplication] delegate]).tabBarController.selectedIndex = 2;

As for the tableview delegate method, ArticleListViewController sounds like the place where you'd want that. The cells should just be dumb views with minor presentation logic at most. If it is not getting called, make sure you've set it up as a delegate for the table view properly (in interface builder if you followed that tutorial you linked to).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top