0

I am doing an animation, so when you click a button MyAccount from the first screen it will navigate you to Account View

- (void)pushToAccount
{
    AccountViewController *controller = [[AccountViewController alloc] initWithNibName:@"AccountViewController" bundle:nil];
    //[self.navigationController pushViewController:controller animated:NO];

    [UIView  beginAnimations: @"Showinfo"context: nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [self.view addSubview:controller.view];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
    [UIView commitAnimations];

}

However, whenever i click on the Account View Controller ( contains some buttons and images view in it ), my program is crashing at it show EXC_BAD_ACCESS at main class

Please advice me on this issue...

rockeye
  • 2,765
  • 2
  • 30
  • 44
tranvutuan
  • 6,089
  • 8
  • 47
  • 83

3 Answers3

1

Your view controller is trying to animate a transition by adding another view controller's view as a subview of your current view. That's problematic on a whole bunch of dimensions. Notably, you're not doing anything with the new view controller itself ... if this was an ARC project, it will get released on you.

If you just want to transition from one view controller to another, you should generally either do a standard pushViewController:animated: or presentModalViewController:animated:. It looks like you used to do the former. Why did you replace it with the current code?

If you can tell us what you were trying to do, why you're not using the standard transitions, perhaps we can help you further.

Update:

If you don't like the default animation, but rather want some custom animation to your transition, you can do something like:

CustomAnimationViewController *yourNewViewController = [[CustomAnimationViewController alloc] initWithNibName:@"CustomAnimationView" bundle:nil];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:yourNewViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

// if you're using ARC, you don't need this following release, but if you're not using ARC, remember to release it

// [yourNewViewController release];

Update 2:

And, anticipating the logical follow-up question, how do you animate the dismissal of the new view controller, you might, for example have a "done" button that invokes a method like the following:

- (IBAction)doneButton:(id)sender 
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelay:0.375];
    [self.navigationController popViewControllerAnimated:NO];
    [UIView commitAnimations];
}
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • what I am trying to do is to animate the transition. Firstly,I followed the tutorial at [here](http://www.devx.com/wireless/Article/42476/0/page/3) and they use `addSubview`.However.Later on, I also found another solution from stackOverFlow at [here](http://stackoverflow.com/questions/3838219/showing-pushviewcontroller-animation-look-like-presentmodalviewcontroller) and they are all about to animate the transition.Therefore,when I did it, I were getting crash in the middle of the way but I did not have the solution for the error at all – tranvutuan Jun 01 '12 at 15:49
  • @ttran I think that first solution is pretty bad (not ARC friendly, not preserving the navigationController stack, etc.), but that second solution is solid. I've updated my answer accordingly with a custom animation, preserving the `pushViewController` invocation. I just tested it and it works fine. – Rob Jun 01 '12 at 16:14
  • 1
    @ttran Anticipating that you'd next ask how to animate the dismissal of the new view controller, I've updated my answer accordingly. – Rob Jun 01 '12 at 16:39
0

My guess is that you have a UIButton that will call your pushToAccount method when pressed and that when it is pressed it cannot find that method. It coud be because the method signature does not include an object. So if you change your method from

- (void)pushToAccount

to

- (void)pushToAccount:(id)sender

It may fix your problem. It is also important to make sure that the object that contains the pushToAccount method isn't dealloc'd before that method is called. Perhaps put an NSLog message or a breakpoint inside dealloc to make sure it isn't called.

DHamrick
  • 8,338
  • 9
  • 45
  • 62
0

i think use bellow line

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES];

insted of your bellow line..

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];

hope this help you... :) and also for animation use bellow code if required....

CATransition *animation = [CATransition animation];
    [animation setDelegate:self];   
    [animation setType:kCATransitionFromBottom];
    [animation setDuration:1.0];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                  kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.window layer] addAnimation:animation forKey:kAnimationKey];

here use your view insted of window otherwise windows workfine.. :)

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • my account view does not have window property. it is the just view and some controllers on it.. – tranvutuan Jun 01 '12 at 13:25
  • yes. Instead of doing `[self.view addSubview:controller.view];` i use `[self.navigationController pushViewController: controller animated:NO];` and it works but I dont know why at all – tranvutuan Jun 01 '12 at 13:32
  • for animation if you define code in delgate method and then use it then its work fine otherwise use AppDelegate object and then define objAppdelegate.window .... its work – Paras Joshi Jun 01 '12 at 13:32
  • then try to addsubview exact line of [view commitAnimation] and other codes are above of addsubview line just try..... – Paras Joshi Jun 01 '12 at 13:35