gpt4 book ai didi

ios - 保留计数并从Fromview移除

转载 作者:行者123 更新时间:2023-12-01 18:18:39 25 4
gpt4 key购买 nike

我有一个UIView,初始化时它已经保留了2,我不明白为什么,因此无法使用removefromsuperview将其删除

ViewController.h

  @property (nonatomic, retain)FinalAlgView * drawView;

ViewController.m
  self.drawView =[[FinalAlgView alloc]init];

NSLog(@"the retain count 1 of drawView is %d", [self.drawView retainCount]);
//the retain count 1 of drawView is 2

[self.bookReader addSubview:self.drawView];

NSLog(@"the retain count 2 of drawView is %d", [self.drawView retainCount]);
//the retain count 2 of drawView is 3

[self.drawView release];

NSLog(@"the retain count 3 of drawView is %d", [self.drawView retainCount]);
//the retain count 3 of drawView is 2

[UIView animateWithDuration:0.2
animations:^{self.drawView.alpha = 0.0;}
completion:^(BOOL finished){ [self.drawView removeFromSuperview];
}];
//do not remove

我不使用ARC

最佳答案

您不能指望retainCount会导致混乱的结果,最好不要使用它。

Apple:

...从这种方法中很难获得有用的信息。

关于ios - 保留计数并从Fromview移除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19132240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com