Accessing a superview (or similar results)

Discussion in 'iOS Programming' started by Delta-NC, Jan 30, 2009.

  1. Delta-NC macrumors member

    Delta-NC

    Joined:
    Apr 22, 2008
    Location:
    Scotland, European Union
    #1
    Just getting myself used to coding the Mac way (and with MVC) and for practice I made a wee app to read a few RSS feeds with a TabBar app.

    Initially I had three separate table views and three classes to go along with it. Once that worked I realised I could simply recycle the same nib with each class, and did so.

    Noticing that I have a lot of repeated code within three separate classes I then went about trying to achieve the same results with a single class, simply changing the feed location string.

    This is where I've hit a problem and I've been stuck for an hour or so thinking about it. Is there any way to tell which tab has been pressed in the super view? What would be the best way to go about this? I feel that my lack of MVC experience may be causing me to miss something obvious.

    Thanks in advance for any advice.
     
  2. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
    Make your app delegate a UITabBarControllerDelegate, then you can use

    Code:
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    to catch when a user selects a view controller from the tab bar.
     
  3. Delta-NC thread starter macrumors member

    Delta-NC

    Joined:
    Apr 22, 2008
    Location:
    Scotland, European Union
    #3
    Wont this return the actual selected view controller? As (in my case) the same one every time? Or is this a view controller for each tab item?

    I must say I'm finding all this incredibly confusing compared to other languages I have used. :confused:
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    You need a separate view controller for each tab. They can be instances of the same class but you need a separate instance for each tab.
     
  5. Delta-NC thread starter macrumors member

    Delta-NC

    Joined:
    Apr 22, 2008
    Location:
    Scotland, European Union
    #5
    Thanks guys. :) I moved all the meat into a new class and then made three small subclasses. Not sure if this was the most efficient way of doing it but it works.
     

Share This Page