你好,我是在iOS的內存管理新我的問題是,當我從認爲時間內存不減少刪除視圖子視圖。在我的嘗試做出可重用的觀點。有3個視圖是主顯示視圖。當使用swap那個時候所有的樹視圖位置都是變化的,並且子視圖存放在NSMutableArray
。但是當我刪除3視圖子視圖時,它不釋放內存。我的代碼是在arc=YES
和我的代碼是Bellow如何從視圖中移除子視圖,並釋放內存
int Position = 0;
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
// Setting the swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
// Adding the swipe gesture on image view
[self.view addGestureRecognizer:swipeLeft];
[self.view addGestureRecognizer:swipeRight];
Position = 0;
Arr_view = [[NSMutableArray alloc] initWithObjects:View_D1,View_D2,View_D3,View_D4,View_D5,View_D6,View_D7,View_D8,View_D9,View_D10,View_D11,View_D12,View_D13,View_D14 nil];
[View_D1 setFrame:CGRectMake(0, 0, 320, 568)];
[View_D2 setFrame:CGRectMake(320, 0, 320, 568)];
[View_D3 setFrame:CGRectMake(640, 0, 320, 568)];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
{
Position++;
}
if (swipe.direction == UISwipeGestureRecognizerDirectionRight)
{
Position--;
}
if (Position>=0 && Position<Arr_view.count)
{
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(ChangePosition) userInfo:nil repeats:NO];
}
else {
if (Position<0) {
Position=0;
}
else {
Position = Arr_view.count-1;
}
}
}
-(void)ChangePosition
{
if (Position%3 == 0) {
[View_D1 addSubview:(UIView *)[Arr_view objectAtIndex:Position]];
[View_D1 setFrame:CGRectMake(0, 0, 320, 568)];
[View_D2 setFrame:CGRectMake(320, 0, 320, 568)];
[View_D3 setFrame:CGRectMake(640, 0, 320, 568)];
[[View_D3 subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[[View_D2 subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
else if (Position%3 == 1) {
[View_D2 addSubview:(UIView *)[Arr_view objectAtIndex:Position]];
[View_D1 setFrame:CGRectMake(640, 0, 320, 568)];
[View_D2 setFrame:CGRectMake(0, 0, 320, 568)];
[View_D3 setFrame:CGRectMake(320, 0, 320, 568)];
[[View_D1 subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[[View_D3 subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
else {
[View_D3 addSubview:(UIView *)[Arr_view objectAtIndex:Position]];
[View_D1 setFrame:CGRectMake(320, 0, 320, 568)];
[View_D2 setFrame:CGRectMake(640, 0, 320, 568)];
[View_D3 setFrame:CGRectMake(0, 0, 320, 568)];
[[View_D1 subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[[View_D2 subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
}
感謝您的重播 – 2014-11-01 13:23:10