创建 UIView 的奇怪问题

发布于 2024-12-19 06:32:20 字数 901 浏览 4 评论 0原文

1>第一个项目: 我创建了一个基于窗口的可可触摸应用程序只是为了测试,它简单明了。 它基本上只是从 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];

}

它工作正常,只给我一个简单的图像视图。

2>第二个项目

但是当我尝试将这些代码集成到另一个可可项目中作为导航

控制器的第一个视图时,它只给我一个白色的空白屏幕。

我基本上在界面生成器(在导航控制器/视图控制器下)“NIB 名称”中指定了 Nib 文件,它只加载一个白色的空白视图,就好像添加图像视图的代码不起作用一样。为什么 ??? 顺便说一句,上面的 viewdidload 代码确实在我在那里放置断点时运行,但它没有给我图像视图。

我注意到的一件事是,当我使用 Interface build 创建 UIImageView 而不是通过 viewdidload 中的代码创建 UIImageView 时,它在第二个项目中工作正常。

所以我想知道为什么代码对于第二个项目不能正常工作以及如何使用代码使其工作?

非常感谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸印温柔 2024-12-26 06:32:20

您的视图是否已连接到 ViewControllers 视图插座?我唯一能想到的另一件事是,也许你没有将 iPod.jpg 包含在第二个项目中?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文