Let’s say I have a tabbar application that nests a lot of uitableviewcontrollers and uiviewcontrollers. What is the line of code that i would use to get a handle on a particular controller?
For example, let’s say I want to grab the uitableviewcontroller which is currently the 3rd tab of the tab bar controller. I am in the MyObject.h/m file which has the following code:
MyObject.h
#import <Foundation/Foundation.h>
#import "MyAppDelegate.h"
@interface MyObject : NSObject
-(void) myfunction;
@end
MyObject.m
#import "MyObject.h"
@implementation MyObject
-(void) myfunction {
UITableViewController * mytvc = /*Some line of code*/;
}
@end
What do i replace /*Some line of code*/ with such that mytvc is a variable that points to the uitableviewcontroller i’m interested in?
I am using XCode 4.2. I have a storyboard that illustrates each of my uiviewcontrollers. The Tabbar view controller was the first thing xcode made for me. So I think that means it’s the top of the app?
If it is your root view controller, and you have access to your app delegate, you should be able to access your controller like this: