UIViewController - 无法通过 IBOutlet 更改 vcontroller.view 内的图像

发布于 2024-12-02 19:43:56 字数 934 浏览 2 评论 0原文

好吧,我昨晚使用了与此类似的解决方法......但是解决方法不足以满足我的新情况,所以我想我应该找出我缺少的内容。

我有一个 UIViewController,它有一个主 UIView 项目、2 个 UIButton 对象和一个 UIImageView。我将文件的所有者设置为我的视图控制器类。 ViewController 有一个类变量“IBOutlet UIImageView * backgroundImage”。我已经在 Interface Builder 中设置了插座,以便 UIImageView 引用“backgroundImage”属性。

我认为此时我应该能够更改 UIImageView 项目。然而,事实并非如此。我可以在代码中设置它,并且我的应用程序不会崩溃(由于缺少插座设置或其他原因),但图像根本没有改变。昨晚我正在尝试与此非常相似的操作,其中我在 ViewController 的根 UIView 项中有一个 UIView,并且我试图将其引用到一个类变量以专门控制该视图。然而,这也没有奏效。

如何控制(通过 IB 和出口)UIViewController.view 的子视图项?

明确地说,这是我的设置:

UINavigationController --> UITableViewController (tvc)

从“tvc”中推送一个新的 UIViewController(vc,注意这不是一个表)。 <-- 这就是我上面描述的内容

在“vc”(UIViewController)中:

  • File's Owner = MyDetailsViewController(UIViewController 的子类)
  • UIView
    • UIImageView <-- 这是我要具体控制的内容,如上所述
    • 按钮
    • 按钮

Ok, I used a work-around for something similar to this last night...but a workaround won't suffice for my new situation, so I figured I should find out what I'm missing.

I have a UIViewController that has a main UIView item, and 2 UIButton objects and a UIImageView. I have the File's Owner set to my view controller class. The ViewController has a class variable "IBOutlet UIImageView * backgroundImage". I have set the outlet in Interface Builder such that the UIImageView references the "backgroundImage" property.

I would assume at this point that I should be able to change the UIImageView item. However, this is not the case. I can set it in code, and my app does NOT blow up (due to a lack of outlet setting or anything), but the image simply doesn't change. I was trying something VERY similar to this last night where I had a UIView within the root UIView item of the ViewController and I was trying to reference that to a class variable to specifically control that view. However, that never worked either.

How can I control (via IB and outlets) the subview items of a UIViewController.view?

Just to be explicit, here is my setup:

UINavigationController
--> UITableViewController (tvc)

From the "tvc", push a new UIViewController (vc, notice this isn't a table). <-- This is what I'm describing above

In the "vc" (UIViewController):

  • File's Owner = MyDetailsViewController (subclassed from UIViewController)
  • UIView
    • UIImageView <-- This is what I'm trying to control specifically, as mentioned above
    • Button
    • Button

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

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

发布评论

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

评论(1

秋心╮凉 2024-12-09 19:43:56

您是否为 UIImageView 设置实际图像

backgroundImage.image = [UIImage imageNamed:@"myImage.png"];  
//(Where myImage.png has been added to to your project)

Are you setting the actual image for the UIImageView like

backgroundImage.image = [UIImage imageNamed:@"myImage.png"];  
//(Where myImage.png has been added to to your project)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文