Correct way to switch between UIView with ARC. My way leads to memory leaks :( (iOS)
Posted
by
Andrei Golubev
on Stack Overflow
See other posts from Stack Overflow
or by Andrei Golubev
Published on 2012-08-28T21:33:08Z
Indexed on
2012/08/28
21:38 UTC
Read the original article
Hit count: 208
i use xcode 4.4 with ARC on..
I have dynamically created UIViews in the ViewController.m:
UIView*myviews[10];
Then in the - (void)viewDidLoad function i fill each of it with pictures i need
myviews[viewIndex] = [[UIView alloc]initWithFrame:myrec];
UIImage *testImg;
UIImageView * testImgView;
testImg = [UIImage imageNamed:[NSString stringWithFormat:@"imgarray%d.png", viewIndex];
testImgView.image = testImg;
viewindex++;
So all seems to be fine, when i want to jump from one view to another i do with two buttons next:
[self.view addSubview:views[viewIndex]];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0f];
[animation setType:@"rippleEffect"];
[animation setSubtype:kCATransitionFromTop];
//[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:animation forKey:@"transitionViewAnimation"];
Nothing seems to be bad, but the memory consumption grows with huge speed when i switch between views.. and then i get low memory warning or sometimes application will just crash.
I have tried to use UIViewController array and was switching between the controllers: nothing changes, the memory low warning is what i end up with..
Maybe i need to clean the memory somehow? But how? ARC does not allow to use release and so on..
last what i have tried (sorry, maybe not very professional) before to add new subview is this
NSArray *viewsToRemove = [self.view subviews];
for (UIView *views in viewsToRemove) {
[views removeFromSuperview];
}
But this does not help either..
Please don't judge too strong, i am still new to iOS and Objective-c..
© Stack Overflow or respective owner