Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么指向故事板中静态单元格的IBMoutletCollection返回null?_Iphone_Storyboard_Iboutlet - Fatal编程技术网

Iphone 为什么指向故事板中静态单元格的IBMoutletCollection返回null?

Iphone 为什么指向故事板中静态单元格的IBMoutletCollection返回null?,iphone,storyboard,iboutlet,Iphone,Storyboard,Iboutlet,我在代码中定义了这一点: @property (nonatomic, weak) IBOutletCollection(UITableViewCell) NSSet * certaintyCells; 合成。我绝对确保这个控制器用于故事板,并将三个单元连接到这个集合 接下来,在didSelectRowAtIndexPath:方法调用中,我添加了此代码,并添加了用于调试的NSLog: NSLog(@"Certainty Cells: %@",certaintyCells);

我在代码中定义了这一点:

@property (nonatomic, weak) IBOutletCollection(UITableViewCell) NSSet * certaintyCells;
合成。我绝对确保这个控制器用于故事板,并将三个单元连接到这个集合

接下来,在
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];
        }
输出如下:

Certainty Cells: (null)
当然,预期的行为不会发生

你知道为什么会这样吗?我确实确保我使用的是静态单元,而不是动态原型。作为旁注,这三个单元也连接到它们自己的(工作)IB插座


谢谢,

我通过做出当时对我没有意义的改变找到了答案我将属性从
更改为
strong
,它成功了。

我当初为什么(软弱):

因为如果视图由于内存警告等原因决定卸载,我不想阻止某些内容被释放

为什么这种想法是错误的:

因为IBOutletCollection是NSSet或NSArray的实例。该NSSet/NSArray不被视图保留,因为它本身不是子视图。对于IBOutlet,弱属性是可以的,对于IBOutletCollection,需要强属性,否则引用计数立即为零,并且它被解除分配


我把这个放在这里,希望它能帮助其他人。

我想说(null)值是释放对象的结果,因为ARC猜测该对象没有被任何人引用,并将值设置为nil,然后在某个时候取消分配它。

同样认为,在apple文档中找不到答案。将其更改为strong,现在可以使用了。我不知道它是否会被解除。。有人吗?它应该在视图控制器解除锁定时自动解除锁定,如果您希望在viewDidUnload中解除锁定,可以在viewDidUnload中将其设置为nil。