1

In my app, you click a button which reveals another page. Whenever you click a button on the view it crashes and shows this:

imege

IBAction on the button:

- (IBAction)searchOptions:(id)sender {
    FilterViewController *ctrl = [[FilterViewController alloc] init];
    [UIView transitionFromView:self.view toView:ctrl.view duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:nil];

    [self.navigationController pushViewController:ctrl animated:NO];
}

In the .h file I have a forward class declaration and set the property:

#import "FilterViewController.h"
@class FilterViewController;
@property (strong) FilterViewController *filterViewController;

I am unsure what is going on here!

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
Josh Boothe
  • 1,413
  • 4
  • 25
  • 40
  • Have a look at http://stackoverflow.com/questions/2215672/how-to-change-the-push-and-pop-animations-in-a-navigation-based-app, perhaps you can use that code. – Martin R Apr 19 '13 at 15:16
  • You should set an exception breakpoint to see what line causes it. The plus button at the bottom of the breakpoints pane will let you add a breakpoint for exceptions. – Brendon Apr 19 '13 at 16:24

2 Answers2

3

Assuming you are using ARC, your ctrl instance is never kept so it is released and deallocated. You need to keep a strong reference to the object.

Perhaps assigning ctrl to the filterViewController property is was you meant to do.

- (IBAction)searchOptions:(id)sender {
    FilterViewController *ctrl = [[FilterViewController alloc] init];
    [UIView transitionFromView:self.view toView:ctrl.view duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:nil];

    self.filterViewController = ctrl;

    [self.navigationController pushViewController:ctrl animated:NO];
}

Update:

Never mind. I totally missed the last line where you push ctrl onto the nab controller. Given this, my initial answer isn't correct at all.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Hi! Thanks for this! Why is the ctrl not kept? I will mark as accepted when it allows me to! If i want to make an IBAction to get rid of the screen presented, do I need to pop the controller only or will I need to set an animation on it? I get a SIGABRT when trying to pop – Josh Boothe Apr 19 '13 at 15:02
  • `ctrl` was being released because nothing in your code kept a reference to the object beyond the `searchOptions:` method. You added a reference to the view, but not the view controller. Again, this is all assuming you are using ARC. – rmaddy Apr 19 '13 at 15:06
  • I just wonder because I am almost sure that `pushViewController` retains `ctrl`. Or is this something special with the transition/animation? – Martin R Apr 19 '13 at 15:07
  • @MartinR Oops - I must have blinders on. Somehow I didn't notice that `ctrl` was being referenced in the call to `pushViewController`. That changes everything. I think I need to delete my answer because now I don't know this is happening. – rmaddy Apr 19 '13 at 15:11
  • 1
    @JoshBoothe See my update. Thanks to Martin's comment, my answer is currently incorrect (though it may still turn out to be the right solution in the end). When do you actually get the error? Is it after you dismiss the `FilterViewController`, before you show it, or while it is displayed? – rmaddy Apr 19 '13 at 15:14
0

In your - (IBAction)searchOptions:(id)sender do this instead

- (IBAction)searchOptions:(id)sender {
    self.filterViewController = [[FilterViewController alloc] init];
    [UIView transitionFromView:self.view self.filterViewController.view duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:nil];

    [self.navigationController pushViewController:self.filterViewController animated:NO];
}