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

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.

Related

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.

iOS6 ScrollBarShouldScrollToTop not firing/ ScrollView Delegate issue

I am adding a dummy ScrollView to my app to detect a user click on the status bar, to performa an event in my program.. I am creating it in the ViewDidLoad:
//Dummy Scroll is for the tap on status bar to work
UIScrollView *dummyScrollView = [[UIScrollView alloc] init];
dummyScrollView.delegate = self;
[[self view ] addSubview:dummyScrollView];
[[self view] sendSubviewToBack:dummyScrollView];
I then implement :
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
NSLog(#"scrollViewShouldScrollToTop");
.
.
}
Under all previous versions of IOS this has worked beautifully and flawlessly, yet under iOS 6 the scrollViewShouldScrollToTop never gets called. Is this a bug?? The API says this should still be available as part of the delegate in iOS6, yet under iOS6 on both device and simulator it never executes... Anyone have any idea what is going on?
Still no other TableView or ScrollView, but there is a MAPVIEW?? But the MapView doesn't have a shouldScrollToTop that I can find to set to NO.. so I am still beyond confused why this stopped working under iOS 6...
Is there any chance that the UIScrollView you're creating isn't somehow the only UIScrollView in your view hierarchy? It looks like in iOS6, if you have more than a single UIScrollView in your view hierarchy, only one should have scrollsToTop = YES. This is the one that'll have its scrollViewShouldScrollToTop method called.
My problem was similar in that I had a very basic UITableView that would no longer autoscroll to the top when the status bar was tapped. I finally remembered that one of the cells in my tableView uses a UIWebView, and that the cell's webView.scrollView was (correctly, now in iOS6) hijacking the call to scrollViewShouldScrollToTop that, before iOS6, was being made on my tableView.
After setting the tableViewCell's "scrollsToTop = NO", the status bar autoscroll once again worked as it did before. Here's more-or-less how the code looks:
myCustomCellWithAWebView.webView.scrollView.scrollsToTop = NO;
Hope this helps!
On iOS 6, only tap the part above scrollview of status bar can fire scrollsToTop event.
And, that scrollView can't be hidden or 0 alpha.
But it can be covered. or clear background color.
So on iOS 6, you need
dummyScrollView.frame = self.view.bounds;
dummyScrollView.backgroundColor = [UIColor clearColor];

When a view is dismissed, the presenting view throws EXC_BAD_ACCESS

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!

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];

Xcode: UINavigationController in a subview

I'm new in Xcode (and also here, in stack overflow) and I'm trying to build an application which contains a small UINavigationController (with a TableView inside) on the top of the window. So it should not be in full screen, it's just a little part of the GUI (just like a textField, or any other kind of component).
I've read that UINavigationController is designed to be displayed on the entire screen, but would it be possible to do it anyway?
If I can't, I'll probably have to write my own UINavigationController-like and TableViewController-like, with all transition effect (between 2 TableView) etcetera...
Thanks in advance for your help!
I founded the solution in a book and it's quite simple. I have to create the UINavigationViewController programmatically:
tableViewController = [[MyTableViewController alloc] initWithNibName:#"MyTableViewController" bundle:nil];
navCtrl = [[NavigViewController alloc] initWithRootViewController:tableViewController];
[navCtrl.view setFrame:CGRectMake(40, 40, 150, 200)];
[window addSubview:navCtrl.view];
[self.window makeKeyAndVisible];

Resources