Switching views crashes app - ios

This is a very odd problem.
I include the .h file of the next view:
#import "MainGame.h"
The I have this code to switch rooms when I press the screen:
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
MainGame *newview = [[MainGame alloc] initWithNibName:#"MainGame" bundle:nil];
newview.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:newview animated:YES completion:NULL];
}
And it works fine in the iOS 5 simulator; but when I test it on my iPod running iOS 4.2 it always just crashes.
All my IBOutlets are connected correctly and everything, as I've already said it works fine in the simulator but not on my iPod.
I have had each individual view working on my iPod before, so I am not using any features which require iOS 5 or anything; it's just this code that switches views that is not working.
Am I missing something?
Thanks!

I believe its a version issue
[self presentViewController:newview animated:YES completion:NULL];
doesn't exist in iOS 4.2 but does in iOS 5
try this instead
[self presentModalViewController:newview animated:YES];

According to the Apple documentation, presentViewController is iOS 5.0 and above.

Related

How to handle the autorotation in each view controller in ios 8?

The scenario is like this:
lets say ViewControllers A, B.
A supports only portrait mode. B supports all modes.
I tap on thumbnail image from A and showing full image in B. So auto-rotation works fine in B. It works fine, If I come back to A from B when B is in portrait mode.
But the problem is if I keep my phone in landscape mode when I was in B then if I come back to A then it is also showing landscape which is not supposed to happen.
I was working totally fine in iOS7 but it is messing up in iOS 8.
Can anyone help with this? Thanks in advance.
Something is wrong with your code. I just implemented it to test and it works fine.
I addded to A:
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Added to B:
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
and added the button to A to open B:
- (IBAction) buttonAction:(id)sender
{
UIStoryboard *story = [UIStoryboard storyboardWithName:#"itShouldWork" bundle:nil];
MyViewController *controller = (MyViewController *)[story instantiateInitialViewController];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentViewController:nav animated:YES completion:nil];
}
As I said, it works fine. tested on iphone 5 device (iOS 8). Built with Xcode 6
It appears to be a bug in iOS 8.
As a workaround you can wrap your B controller in UINavigationController. Along with checking for iOS version it would look like
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8")) {
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:controllerB] animated:YES completion:nil];
} else {
[self presentViewController:controllerB animated:YES completion:nil];
}
Macros for checking iOS version can be found here.

UIModalPresentationPageSheet Gives different view in iOS8

UIModalPresentationPageSheet is not working in iOS8.
MyViewController *myViewController=[[MyViewController alloc] init];
myViewController.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:myViewController animated:YES completion:nil];
This code works just fine in iOS6 and iOS7. But with iOS8 it just gives a full screen view just like UIModalPresentationFullScreen.
How can I have iOS7-UIModalPresentationPageSheet-like view in iOS8? Thanks in advance.
Looks like an early beta bug. Make sure to open a bug report with Apple at https://bugreport.apple.com.

iPad Mini crashing on modal segue

I am developing an app that runs on all the deployment target simulators (5.0-6.1) and on my iPhone 3GS, 4, 4S and a gen 2 iPad. I had the opportunity today to try running it on an iPad Mini. I works everywhere except when I try to segue to a MFMailComposeViewController object to send an email, which causes it to crash with an exception.
I use the code directly from the MailComposer sample project, but it always crashes when it calls presentModalViewController:animated:. So I tried presentViewController:animated:completion: as the other method is deprecated, but it still doesn't work.
I linked to MessageUI.framework imported the classes:
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
The delegate is set. Here is the code:
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Contact Email"];
// Set up recipient
NSArray *toRecipients = [NSArray arrayWithObject:#"info#foo.bar"];
[picker setToRecipients:toRecipients];
// [self presentModalViewController:picker animated:YES];
[self presentViewController:picker animated:YES completion:NULL];
}
Might there be a bug causing this in the iPad Mini? I don't have any other new devices I can try it on so I'm not sure if its a Mini problem or something bigger. Any help would be appreciated as I'm ready to submit to Apple but I sure don't want to do that with a crashing bug.
It's likely that a mail account has not been set up or for some other reason cannot send email.
Be sure to call the + (BOOL)canSendMail function of MFMailComposeViewController first.
Try wrapping your MFMailComposeViewController code with
if ( [MFMailCompseViewController canSendMail])
I'd guess the device doesn't have mail setup on it.

iOS 5.1.1 Popover not dismissing automatically

My application works well on older OS' but on 5.1.1 (tested on both iPad2 and new iPad) popover shows up, runs well but does not dismiss when user taps outside the popover. I do not use any dismissal code or buttons. I used iOS 5.0 SDK, XCode 4.2 to compile the app. Here's how I show it up. Any ideas what could be wrong?
- (void)showNotifications {
NotificationsViewController *vc = [[[NotificationsViewController alloc] init] autorelease];
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
if ([UIApplication isIPad]) {
vc.modalInPopover = YES;
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:vc] autorelease];
[self.popoverController presentPopoverFromRect:bottomView.frame inView:[bottomView superview] permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
else
[self presentModalViewController:vc animated:YES];
}
Mystery solved. Just commented out the line
//vc.modalInPopover = YES; must be no on iOS 5
ModalInPopover must be false on iOS 5. Don't know if it still works on iOS 4 though.

PresentViewController crash on iOS 4.3 but not on iOS 5

Can anyone tell me why this code crashes with SIGABRT unrecognised selector sent to instance, on 4.3 simulator, but works just fine on iOS 5 simulator?
matchSetup = [[viewMatchSetup alloc]initWithNibName:#"viewMatchSetup" bundle:nil];
[matchSetup setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:matchSetup animated:YES completion:NULL];
Thanks in advance
FIX: [self presentModalViewController:matchSetup animated:YES]; //Modal being the required change
It crashes because the presentViewController:animated:completion: method of UIViewController is not available on iOS 4.3. It was introduced in iOS 5. Since you don't use the completion block, simply use the "old" method presentModalViewController:animated::
[self presentModalViewController:matchSetup animated:YES];

Resources