简体   繁体   中英

Strange issue for creating a UIView

1>1st project : I have created a window based cocoa touch app just for test, it's straight forward and easy. It's basically just loading the view from the Nib file but have some code in the

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIImage * image = [UIImage imageNamed:@"ipod.jpg"];
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

    UIImageView* imageView = [[UIImageView alloc] initWithFrame:applicationFrame];
    imageView.image = image;
    imageView.userInteractionEnabled = YES;

    [self.view addSubview:imageView];

}

It works fine and just give me a simple image view.

2>2nd proejct

But when I trying to integrate those code into another cocoa project as the 1st view of a navigation

controller, it only gives me a white blank screen.

I basically specified the Nib file in the interface builder(under Navigation controller / view controller) "NIB Name", and it only loads me a white blank view as if the code for adding the image view is not working. Why ??? BTW The viewdidload code above did run as I put a break point there, but it's not giving me the image view.

One thing I did notice is when I create the UIImageView using Interface build instead of doing it by code in viewdidload, it works fine in the 2nd porject .

So I am wondering why the code not working fine for the 2nd project and How to make it work using code?

Many Thanks

Is your view is wired up to the ViewControllers view outlet? The only other thing I can think of is that maybe you don't have iPod.jpg included in the second project?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM