简体   繁体   English

创建UIView的奇怪问题

[英]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. 1>第一个项目:我已经创建了一个仅用于测试的基于窗口的可可触摸应用程序,它简单直接。 It's basically just loading the view from the Nib file but have some code in the 它基本上只是从Nib文件加载视图,但是在

- (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 2>第二个项目

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. 我基本上在界面构建器(位于导航控制器/视图控制器下)“ NIB Name”中指定了Nib文件,并且它仅向我加载一个白色空白视图,好像添加图像视图的代码无法正常工作。 Why ??? 为什么??? BTW The viewdidload code above did run as I put a break point there, but it's not giving me the image view. 顺便说一句,当我在此处放置一个断点时,上面的viewdidload代码确实运行了,但是它没有给我图像视图。

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 . 我注意到的一件事是,当我使用Interface构建而不是通过viewdidload中的代码创建UIImageView时,它在第二个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? 您的视图是否已连接到ViewControllers视图插座? The only other thing I can think of is that maybe you don't have iPod.jpg included in the second project? 我唯一想到的另一件事是,也许您没有在第二个项目中包含iPod.jpg?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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