1

I am adding a subview to my finalview which is used to change prefrences on the app. I add it like this from my finalview

getPrefrencesViewController = [[GetPrefrencesViewController alloc] init];
getPrefrencesViewController.view setBackgroundColor:[UIColor clearColor]];

getPrefrencesViewController.view.frame = CGRectMake(0.0, 480.0, 320.0, 480.0);

getPrefrencesViewController.prefToolBar.frame = CGRectMake(0.0, 9.0, 320.0, 45.0);
[getPrefrencesViewController.view addSubview:getPrefrencesViewController.prefToolBar];

getPrefrencesViewController.prefTableView.frame = CGRectMake(0.0, 54.0, 320.0, 435.0);
[getPrefrencesViewController.view addSubview:getPrefrencesViewController.prefTableView];


[self.navigationController.view insertSubview:getPrefrencesViewController.view aboveSubview:self.navigationController.view];




            [UIView animateWithDuration:0.3
                                  delay:0.0f
                                options:UIViewAnimationOptionCurveEaseIn
                             animations:^{

                                 getPrefrencesViewController.view.frame = CGRectMake(0.0, 10.0, 320.0, 480.0);

                             } completion:^(BOOL finished) {
                                 if (finished) {
                                     NSLog(@"YAY!");
                                 }
                             }];
        }

This works fine...

When the new view is added as a subview I have a UIToolBar with two buttons save and cancel, when the user touches cancel this code is used

- (IBAction)cancleUIButton:(id)sender {
    //unload portrait view
    [UIView animateWithDuration:0.4
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{



                         self.view.frame = CGRectMake(0.0, 480.0, 320.0, 480.0); 



                     } completion:^(BOOL finished) {
                         if (finished) {

                             // remove subView for superView
                             [self.view removeFromSuperview];



                         }
                     }];
}

as you can see i add the subview, animate it upwards, then when the user presses cancel I animate the view then remove it from superview.. however if I then load it again all the values I change but not saved are still changed, meaning the view is never removed.

I am hoping someone can tell me why this view is never getting removed? any help would be greatly appreciated.

HurkNburkS
  • 5,332
  • 19
  • 93
  • 176
  • 1
    Have you tried setting the view to nil after you remove it from the superview? – JMarsh Jun 12 '13 at 23:11
  • there must be another strong pointer to point to the `self.view`, which keep the object alive, it could be the view controller's `view` ivar. the object will be released when there is no more strong pointer to keep it alive. in the superview's `subviews` array is just one of the strong pointers. – holex Jun 12 '13 at 23:11
  • self.view = nil; worked – HurkNburkS Jun 12 '13 at 23:37

0 Answers0