PDA

View Full Version : Accessing a superview (or similar results)




Delta-NC
Jan 30, 2009, 06:55 AM
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.



jnic
Jan 30, 2009, 07:49 AM
Make your app delegate a UITabBarControllerDelegate (https://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html), then you can use

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

to catch when a user selects a view controller from the tab bar.

Delta-NC
Jan 30, 2009, 09:44 AM
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:

PhoneyDeveloper
Jan 30, 2009, 11:18 AM
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.

Delta-NC
Jan 31, 2009, 06:00 AM
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.