When a view is dismissed, the presenting view throws EXC_BAD_ACCESS - xcode

I'm converting my iPhone app to an iPad version, creating new XIBs for the iPad and rigging them to the existing objective C classes using the ~ipad XIB name.
In the iPhone version, I use the navigation controller to step backwards to the app. This should work just fine in the iPad too, but while the navigation controller does appear, it doesnt respond. In fact its invisible to any interaction, if theres a map behind the navigation controller and you double click back, you just zoom on the map where you clicked.
So I'm including a button in the iPad view which should do the same thing. On press I call a
[[self navigationController] popViewControllerAnimated: YES];
When I call this I get the EXC_BAD_ACCESS. I've gone in to the spooky zombie mode which gives me this
*** -[UIWindowLayer superlayer]: message sent to deallocated instance 0x83bb9f0
Ive determined that 0x83bb9f0 is the presenting layers self.view.layer
I'm using ARC to handle my allocations and deallocs.
THE QUESTION IS: How can I prevent self.view.layer from deallocing? or how can I allocate it again at the proper time so that I dont get this error?
I can provide more code if needed. Thanks so much!!
Edit: Heres where the main page (landing page) is created, and the nav controller
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
landingPage *LandingPage = [[landingPage alloc] initWithNibName:#"landingPage" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:LandingPage];
self.window.rootViewController = self.navigationController;
// [self.navigationController pushViewController:LandingPage animated:YES];
[self.window makeKeyAndVisible];
return YES;
Then here is where the inner view is called:
mapView *MapView = nil;
MapView =[[mapView alloc] initWithNibName:#"mapView" bundle:nil];
[self.navigationController pushViewController:MapView animated:YES];

So I got it!
The XIBs I was creating for the iPad version were windows instead of views. I recreated all of these as views and rigged it up and it worked just fine!

Related

iOS 9 Bug when using presentViewController "EXC_BAD_ACCESS code=2"

First. IT WAS working until this last update from Apple. So in theory it should still work.
Here's the code:
CarouselViewController *cViewController = [[CarouselViewController alloc] initWithContent: edition];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: cViewController];
[self presentViewController: nav animated: YES completion:nil];
The reason i'm doing it is because i need this new window to be presented in fullscreen and not inside this ViewController (the caller) which is occupying half of the screen.
So, HOW can i fix this? And why BEFORE it was working and now with this silly iOS 9 update it isn't?
My guess (and that's all it is with the limited information presented) is that the root cause of the problem has something to do with CarouselViewController and it's view actually being loaded and presented on screen.
That is what is happening in your app during this line
[self presentViewController: nav animated: YES completion:nil]
I would set a breakpoint in that ViewController subclass loadView/viewDidLoad or check out it's Nib/Storyboard.

NSPopover switch view

I have a popover menulet and it's contentViewController is some NSViewController. Everything fine here. The problem that I have is that I really don't understand how to change the View. I wanna load another view, and this is what I tried:
popover = [[NextViewController alloc]initWithNibName:#"NextViewController" bundle:nil];
[self.view addSubview:[popover view]];
And this works, new view is shown - but if I click on any button on that view I get error: unrecognized selector sent to instance. Why am I getting this error? Why this new view is not responding?
Please help me understand what I need to do, how to change the view on NSPopover?
I've managed to solve my problem, It turn out to be quite easy:
[self.view setSubviews:[NSArray array]]; //remove all previous subviews
[self.view addSubview:[popover view]];

Paging in MWPhotoBrowser not working properly after implementing custom tabbar

I'm using MWPhotoBrowser in a project and everything worked great until I implemented a custom tabbar (to make one of the tab items higher and wider). I used RXCustomTabBar as a starting point for my tabbar and only modified it a bit, no meaningful changes though.
After implementing the new tabbar and in the app open the MWPhotoBrowser I can only view the first photo. I can still scroll in the photobrowser but no other photos than the first is shown. Neither can I toggle the "fullScreenLayout" that is implemented in the MWPhotobrowser when I'm not viewing the first photo.
I'm simply confused since I have no idea what is causing this problem. I know it's a far fetched question since it's two custom made libraries I'm working with but perhaps someone has experienced a similar problem in the past. Would be very grateful for suggestions!
This is the code I use to push the MWPhotoBrowser:
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
[self.navigationController pushViewController:browser animated:YES];
I tried presenting the browser modally with:
[self.navigationController presentModalViewController:browser animated:YES];
That way the photos are shown correctly but I have no navigation bar.
After hours of headache I came up with a solution:
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
[browser setInitialPageIndex:indexPath.item];
UINavigationController *navBar = [[UINavigationController alloc] initWithRootViewController:browser];
[self.navigationController presentModalViewController:navBar animated:YES];
I.e. I create a UINavigationController in which I embed my MWPhotoBrowser and then present the navigationcontroller modally.

Info light button Placement and transition

In the apps that i have seen, info light buttons are all in the navigation bar and when touched, the transition to a new view is a horizontal flip. Is it okay if i make an application that does not have the info light button in the navigation bar and when touched, uses the push animation to transfer the user to a new view? If not, could someone tell me how to code for the horizontal flip because when i choose Modal and flip and connect to a view, nothing happens when pressed (but works if if i choose push instead of modal.
Thanks
You can do what ever you want. There is no guideline for what kind of button should cause what kind of view change.
Here's a couple of examples of how to change view controllers:
//if you are using xibs use this line
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"myXib" bundle:[NSBundle mainBundle]];
//if you are using storyboards use this line
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"myViewControllersID"];
[controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
//this sets the modal transition style
//to present the controller modally use this
[self presentViewController:controller animated:YES completion:nil];
//or if you are pushing to this controller using a navigation controller use this
[self.navigationController pushViewController:controller animated:YES];

ios4 - Load new view on clicking a button

I am currently using XCode 3.2.3 and iOS4. I'm working on an app that simply starts with one screen and on a button click moves to the next.
I have gone thorugh the ViewController programming guide and a post here.
What I am doing is very similar to whats happening on the post. So let me explain the steps, I followed:
In IB, drag and drop, a View from the library into the editor. I renamed the new UIView to myView.
In my AppControllerDelegate, I added the new view "myView" as a property of the view controller (File's Owner). I synthesized it as well in the implementation.
Now, in the implementation of the ViewController, within the button pressed action handler, I wrote the following lines of code:
[self.view addSubView: myView];
On clicking the button however, I do not see a new screen or my new view. However if I do this, I get a new screen or new view:
UIView *anotherView = [[UIView alloc] initWithFrame:self.view.frame];
[self.view addSubView: anotherView];
I do know that the best way is to do it with separate NIBs for each UIView. However, I am new to iPhone development and have not explored that path as yet.
My question: What am I missing upto step 3?
One way you could be able to do it is by trying it this way
myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle: [NSBundle mainBundle]];
[self.view addSubview: myView.view];
Try that and see if it is working.. if yours is a view based project then instead of [self.view addSubview: myView.view], just give [self.view addSubview : myView];

Resources