Superview and parentviewcontroller nil after adding subview

I think that I am missing something fundamental, and therefore I want to ask the community for help. I am creating an application based on the basic application for the iPhone. My MainView and FlipsideView have some elements, so I created separate ViewControllers and nib files for these fragments. To do this, I did the following: 1. Created a viewcontroller called searchDateViewController, which is the owner of the searchDateView.xib file 2. searchDateView.xib is basically a UIView with a UILabel inside, the view is connected correctly 3. Inside MainViewController.m and FlipsideViewController.m. I add subview as folllows:

- (void)loadView{
    [super loadView];
    searchDateViewController = [[SearchDateViewController alloc] initWithNibName:@"SearchDateView" bundle:nil];
    [[searchDateViewController view] setFrame:[searchDateView frame]];
    [[self view] addSubview:[searchDateViewController view]];

...
}

Everything displays and works perfectly. Basically, depending on the actions that occur in each of the main and reverse representations, UILabel from nib changes. However, I wanted to do something a little different if the searchDateViewController is loaded from MainView or FlipsideView. However, I cannot figure out which ViewController adds the searchDateViewController routine.

In searchDateViewController, I tried:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"superview %@", self.view.superview);
    NSLog(@"parentviewcontroller %@", self.parentViewController);
}

In both cases, I get zero.

So my question is: can I find out which ViewController adds searchDateViewController a subview? If so, how? Or, if my logic here is completely confused, how can I do this?

Thanks!

+5
source share
2 answers

viewDidLoad , . :

[[searchDateViewController view] setFrame:[searchDateView frame]];

addSubview:, , viewview nil.

, SearchDateViewController, . , SearchDateViewController.

, UIViewController , , . UIViewController , . , , , , SearchDateViewController .. - , SearchDateViewController NSObject.

+2

ViewController .

, subview , viewController. , .

SearchDate viewController , , . , .

searchDateViewController.parentController=self;
-2

All Articles