Search code examples
objective-cipadaddsubview

adding subview of another class


iv created a class with xib so i can access it throughout my app. The class basically holds a nib with has three uiviews and a few buttons buttons+labels. Now im calling class A (the one with 3 view etc) from classB but every time i addsubview to self.view nothing happens. any help appreciated.

ive done the following in class B.h

#import "PlayResultViewController.h"
PlayResultViewController *playResultViewController;

in classB.m

//viewdidload
playResultViewController = [[PlayResultViewController alloc]init];
//some random method
[placeholderView addSubview:playResultViewController.loseView];

Solution

  • You are missing the initWithNibName to start with, here are some examples

    With a Navigation controller u can use

    BViewController *bController = [[BViewController alloc] initWithNibName:@"BViewController" bundle:nil];
    [self.navigationController pushViewController:bController animated:YES];
    [bController release];
    

    without UInavigation controller you can test with

    BViewController *bController = [[BViewController alloc] initWithNibName:@"BViewController" bundle:nil];
        self.view = bController; 
        // or alternatively self.view = bController.view;
        [bController release];