Ale*_*lin 9 iphone storyboard iboutlet
我在代码中定义了这个:
@property (nonatomic, weak) IBOutletCollection(UITableViewCell) NSSet * certaintyCells;
Run Code Online (Sandbox Code Playgroud)
并合成.我绝对确定这个控制器用在故事板上,并将三个单元连接到这个集合.
接下来,在didSelectRowAtIndexPath:方法调用中,我添加了此代码,并添加了NSLog用于调试:
NSLog(@"Certainty Cells: %@",certaintyCells);
for (UITableViewCell * cell in certaintyCells) {
[cell.textLabel setTextColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
}
Run Code Online (Sandbox Code Playgroud)
输出是这样的:
Certainty Cells: (null)
Run Code Online (Sandbox Code Playgroud)
当然,预期的行为不会发生.
关于为什么会发生这种情况的任何想法?我确实确保使用的是静态单元,而不是动态原型.作为旁注,这三个单元也连接到(工作)它们自己的IBOutlet.
谢谢,
Ale*_*lin 36
我通过对当时没有意义的改变找到了答案.我从更改属性weak来strong,和它的工作.
为什么我首先有(弱):
因为如果视图由于内存警告/等而决定卸载,我不想让某些东西被解除分配.
为什么这种想法是错误的:
因为IBOutletCollection是NSSet或NSArray的实例.视图不保留NSSet/NSArray,因为它本身不是子视图.对于IBOutlet,弱属性很好,IBOutletCollection需要强属性,否则引用计数立即为零并且它被释放.
我要离开这里,希望能帮助别人.
| 归档时间: |
|
| 查看次数: |
1931 次 |
| 最近记录: |