gpt4 book ai didi

ios - ARC 和释放应用程序中的内存

转载 作者:行者123 更新时间:2023-11-29 03:24:54 24 4
gpt4 key购买 nike

- (void)viewDidLoad
{

[super viewDidLoad];

self.predictionsObjectArray = [[AAPredictions alloc] init];

[self.predictionsObjectArray setPredictionsArray:@[@"Probably Not", @"Ask Again", @"I doubt it", @"Unlikely", @"I believe so"]];



for (int x = 1; x<61; x++) {
NSMutableString *imageName = [[NSMutableString alloc] init];
if (x > 9) {
imageName = [NSMutableString stringWithFormat:@"CB000%i.png", x];
}
else {
imageName = [NSMutableString stringWithFormat:@"CB0000%i.png", x];
}

[self.animationImagesArray addObject:[UIImage imageNamed:imageName]];

}

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark Prediction

-(void)makePrediction {
self.predictionLabel.text = [self.predictionsObjectArray getPrediction];
[self animateItems];


}
-(void)animateItems {

self.image_button.alpha = 0.0;

self.background_image.animationRepeatCount = 1.0;

self.background_image.animationImages = self.animationImagesArray;

self.background_image.animationDuration = 3.0;
[self.background_image startAnimating];






while (self.background_image.isAnimating) {

}

self.image_button.alpha = 1.0;

}

制作一个简单的 Crystal 球应用程序,并尝试为其制作动画。我确实已经为此工作了一段时间但没有运气。希望有人能在我学习时帮助我,特别是 ARC。我知道我需要在 viewDidLoad 中添加一行函数将引用计数添加到 self.animationImagesArray 的+1 ,因为当我去分配 self.background_image.animationImagesself.animationImagesArray ,ARC发布了它,我知道,因为在底部的调试器中,它的值为nil。任何帮助都会很棒。

最佳答案

格雷迪是正确的。您从未初始化数组。如果你没有像他发布的那样的初始化(对于非常新的人来说可能会造成混淆)就这样做:

//NEW: Initialize the array before adding items to it
self.animationImagesArray = [NSMutableArray new];

for (int x = 1; x<61; x++) {
NSMutableString *imageName = [[NSMutableString alloc] init];
if (x > 9) {
imageName = [NSMutableString stringWithFormat:@"CB000%i.png", x];
}
else {
imageName = [NSMutableString stringWithFormat:@"CB0000%i.png", x];
}

[self.animationImagesArray addObject:[UIImage imageNamed:imageName]];

}

关于ios - ARC 和释放应用程序中的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20578147/

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