在Interface Builder中创建的UIImageView在需要时设置为nil [英] UIImageView Created In Interface Builder Set To nil When Needed

查看:62
本文介绍了在Interface Builder中创建的UIImageView在需要时设置为nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中MainWindow中定义了少量对象。一对这些对象是UIViewController和与该控制器一起使用的UIImageView。当应用程序启动时,整个MainWindow.xib被加载并且我可以看到这个UIImageView已经加载到内存中。此时,我不需要这个UIImageView。

I have an application where small number of objects are defined in the MainWindow. A pair of these objects are a UIViewController and the UIImageView that goes along with this controller. When the application starts up, the entire MainWindow.xib get loaded & I can see that this UIImageView has been loaded into memory. At this point, I have no need for this UIImageView.

当我需要UIViewController时,我执行通常的alloc / init设置。此时,当我使用调试器查看此控制器时,控制器已正确设置,但应与Interface Builder预先连接的UIImageView始终为零。

When I need the UIViewController, I perform the usual alloc/init setup. At this point, when I look at this controller with the debugger, the controller is setup correctly, but the UIImageView that should have been pre-wired with Interface Builder is always nil.

有关如何确保将此UIImageView正确加载到内存中的任何建议吗?这是唯一一个我在这个MainWindow.xib文件中定义对象的问题。

Any suggegstions on how to make sure this UIImageView is loaded into memory correctly? This is the only case where I've had an issue with objects defined within this single MainWindow.xib file.

推荐答案

假设你已连接视图插座,您只需访问视图属性即可。当您查看调试器时,您将看到该属性的相应ivar。当您在代码中访问该属性时,它应该为您加载。所以,它应该简单如下:

Assuming you have connected the view outlet, all you need to do is access the view property. When you look in the debugger, you're seeing the property's corresponding ivar. When you access the property in code, it should load for you. So, it should be as simple as:

  [controller view];

这篇关于在Interface Builder中创建的UIImageView在需要时设置为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆