Ios 这会产生一个保留周期吗?
我了解了保留周期,然后我看了这个视频教程,但我觉得他写的代码包含了保留周期。 所以我想发帖是来征求意见的。下面是代码片段:Ios 这会产生一个保留周期吗?,ios,objective-c,Ios,Objective C,我了解了保留周期,然后我看了这个视频教程,但我觉得他写的代码包含了保留周期。 所以我想发帖是来征求意见的。下面是代码片段: [UIView transitionWithView:self.view duration:.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ self.myImageView.image = randomDog.image; self.B
[UIView transitionWithView:self.view duration:.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.myImageView.image = randomDog.image;
self.BreedLabel.text = randomDog.breed;
self.nameLabel.text = randomDog.name;
} completion:^(BOOL finished) {
}];
因为在块内部正在使用self,并且该块将保持self作为其强指针
我在某个地方读到,若一个人需要在街区的一边使用self,那个么创造一个像self一样的周末总是很好的做法
id (nonatomic, weak) weakSelf;
weakSelf = self;
然后在区块内使用薄弱环节
如果我正确理解了这个概念,请帮助我。提前感谢。在这种情况下,您没有保留周期问题 您确实有保留周期,但它是临时的,不会引起任何问题 保留图形类似(
A->B
表示A保留B)
但在动画块被执行后,它将被销毁并保留图形
self -> view
一切都很好
此外,中断retain循环的正确语法是
__weak __typeof__(self) weakSelf = self;
^ { // inside block
__typeof__(self) strongSelf = weakSelf;
// use strongSelf
}
或者您可以使用
@weakify
和@strongify
从在块内使用self完全可以。特别是如果它是一个简单的动画块(如果它是一个GCD块,它可能会更复杂)。这也是正确的吗????交换弱者和弱者的位置__typeof@Alix对它们是一样的。
__weak __typeof__(self) weakSelf = self;
^ { // inside block
__typeof__(self) strongSelf = weakSelf;
// use strongSelf
}