- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在使用 ARC 专门为 iOS 5 开发。 IBOutlet
s 到 UIView
s(和子类)应该是 strong
还是 weak
?
以下内容:
@property (nonatomic, weak) IBOutlet UIButton *button;
将摆脱所有这些:
- (void)viewDidUnload
{
// ...
self.button = nil;
// ...
}
这样做有什么问题吗?模板使用 strong
以及从“Interface Builder”编辑器直接连接到标题时创建的自动生成的属性,但为什么呢? UIViewController
已经有一个对其 view
的 strong
引用,该引用保留了它的 subview 。
最佳答案
警告,过时的答案:根据 WWDC 2015,此答案不是最新的,正确答案请参阅 accepted answer (丹尼尔霍尔)以上。此答案将留作记录。
总结自 developer library :
From a practical perspective, in iOS and OS X outlets should be defined as declared properties. Outlets should generally be weak, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong. Outlets that you create will therefore typically be weak by default, because:
Outlets that you create to, for example, subviews of a view controller’s view or a window controller’s window, are arbitrary references between objects that do not imply ownership.
The strong outlets are frequently specified by framework classes (for example, UIViewController’s view outlet, or NSWindowController’s window outlet).
@property (weak) IBOutlet MyView *viewContainerSubview;
@property (strong) IBOutlet MyOtherClass *topLevelObject;
关于ios - 在 ARC 下,IBOutlets 应该强还是弱?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7678469/
这个问题在这里已经有了答案: 关闭 10 年前。
我创建了一个自定义单元格: #import #import "SevenSwitch.h" @interface cellaMain : UITableViewCell { SevenSwi
我有一个颜色选择器项目。对于每个颜色组件(红色、绿色和蓝色),我有一个 UIPickerView、一个文本字段和一个步进器。我想做的是创建一个类,我们将其命名为 ColorPickerObject,如
我目前正在使用统一的 Storyboard(带有尺寸等级)。对于我的观点之一,wAny hAny 和 wRegular hRegular 大小类之间的设计差异非常明显,以至于根据大小类更改 subvi
class AClass: UIViewController,CLLocationManagerDelegate,MKMapViewDelegate { @IBOutlet var m
我在同一个 nib 文件中有我的主应用程序 View Controller (文件所有者)、它的第一响应程序、 View 和其他 3 个 UIViewController。 3 个 UIViewCon
我创建了以下自定义 View : @interface TNGalleryView : UIView @property (assign, nonatomic) id delegate; @prop
我制作了一个自定义的 UITableViewCell,我在其中添加了 2 个标签和一个 UIImageView,每个标签都带有 IBOutlets。 IBOutlet weak var imageVi
我的大多数 View Controller 中有几个 socket ,我总是将它们与头文件中的属性链接起来,如下所示: IBOutlet UIButton *homeButton; @property
在大多数示例中,我看到 IBOutlet 的以下设置: (Example A) FooController.h: @interface FooController : UIViewController
我的 EAGLView 类中有一个类“A”的实例,它在 EAGLView 的 initWithCoder 方法中实例化。 此类“A”包含 UIView 的 IBOutlet。 我在 Interface
加快Cocoa iPhone/Mac开发速度,我知道原子和非原子属性之间的区别,以及与非原子的性能差异,但是IBOutlet的每个定义我见过的属性指定非原子的,而不是默认的原子的。我无法找到解释这是一
我正在尝试设置来自不同类的 NSTextField 的文本.. 这就是我所拥有的: 首选项.h @interface Preferences : NSObject { IBOutlet NSTextF
我有一个基于文档的 cocoa 应用程序,应用程序菜单中的一个项目连接到一个IBAction。单击该项目需要执行一项使用主 nib 文件中的 IBOutlet 的任务,该文件使用另一个类 MyDocu
我通过 Interface Builder 设置了 TextView 的导出。 TextView 加载正常,但是我无法以编程方式访问它的任何属性,因为导出始终为 nil。 什么时候实例化?即使在调用我
这是一个我已经被困了两个小时的问题了!我有一个带有静态单元格表 View 的 TableView Controller 。在静态 TableView 单元之一中,我放置了一个带有动态单元的 Tab
是否需要将所有声明为IBOutlet的带有retain修饰符的@property设置为nil - (void)dealloc 方法?如果我不这样做,内存会被消耗/浪费吗? 假设自动引用计数关闭。 最佳
我有A级和子类 ClassB 是否可以将 UIImage 选择器中的图像从 ClassA 传递到 ClassB NSLog(@"Camera Dismiss Method Reached"); [pi
我有 2 个 swift 文件,一个是我的 HomeViewController,第二个是我的 EventCollectionViewCell。在第二个中,我有一个 IBOutlet = inform
我目前正在制作一个路线跟踪应用程序来教我自己如何快速。我具有处理正在跟踪的路线和从单个 SessionController 类中绘制折线的基本功能,但我想将该类拆分为单独的对象。 这就是我遇到问题的地
我是一名优秀的程序员,十分优秀!