Viewdid load method call on popview

222 Views Asked by At

In my application i set some animations in View1's view load() ,At first launch its working propely,if im pushed into otherview ,and while pop into view1 its not animating,What shoud i do for animate while pop view from other view?here my view did load code,

 - (void)viewDidLoad
{
artext=[[NSMutableArray alloc] init];
arimage=[[NSMutableArray alloc] init];
arsound=[[NSMutableArray alloc] init];

[super viewDidLoad];
[self copysqlitetodocuments];
[self Readthesqlitefile];   
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage     imageNamed:@"classroom.png"]];

}

i tried with

  - (void)viewDidAppear:(BOOL)animated
 {
 [self buttonmover];
 [super viewDidAppear:animated];
  }

its not working,Can any one pls help me to solve this problem

3

There are 3 best solutions below

1
Mike Weller On

If you want to execute code when the view appears (e.g. an animation), -viewDidLoad is the wrong place to do it.

You should probably use:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    // ...
}
0
Anki On

Try in viewWillAppear

  -(void)viewWillAppear:(BOOL)animated
 {
  artext=[[NSMutableArray alloc] init];
  arimage=[[NSMutableArray alloc] init];
  arsound=[[NSMutableArray alloc] init];

  [self copysqlitetodocuments];
  [self Readthesqlitefile];   
  self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"classroom.png"]];

 }
4
Marco Pace On

When your viewDidLoad method is called, the controller isn't yet in the view hierarchy, so the animations doesn't work.

You have to perform animations in viewWillApper, after implementing the method [super viewWillAppear]. Something like:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    artext = [[NSMutableArray alloc] init];
    arimage = [[NSMutableArray alloc] init];
    arsound = [[NSMutableArray alloc] init];

    [self copysqlitetodocuments];
    [self Readthesqlitefile];   
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"classroom.png"]];

}