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.
Related
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.
I want to apologize in advance because I am fairly new to programming, so if I am not as specific as I can be I am sorry but I will try to explain my problem as best as I can anyways, I am creating an app that needs to have the ability to send emails and I have looked everywhere, tried every sample code I could find and nothing seems to work every time I use code I get the following error:
2013-02-03 20:23:39.372 Tones[16409:c07] Warning: Attempt to present
on
whose view is not in the window hierarchy!
This is the code I am currently using in the viewcontroller.h file:
UIViewController <MFMailComposeViewControllerDelegate>
- (IBAction)Mail:(id)sender;
and this is in my viewcontroller.m file:
- (IBAction)Mail:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:#"Subject"];
NSArray *recipient = [NSArray arrayWithObjects:#"mail#example.com", nil];
[mail setToRecipients:recipient];
NSString *body = #"body!";
[mail setMessageBody:body isHTML:NO];
[self presentModalViewController:mail animated:YES];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
I also get a message that says both self presentModalViewController and self dismissModalViewController is deprecated in IOS 6 so does that mean I cant use it or am I doing something wrong?
So any help on what I am doing wrong with the mail composer would be much appreciated and again im sorry if I was not specific enough thanks in advance
You can use presentModalViewController:animated: to show the modal viewcontroller, but it is now recommended to use the new one: presentViewController:animated:completion:. The new on owns a completion handler and you can get more control of the code. Be careful the new method required a iOS 5.0 above. If your target is iOS5.0 above, you should use the new method. And the same for dismissModalViewControllerAnimated:, use dismissViewControllerAnimated:completion: instead.
The warning "Warning: Attempt to present on whose view is not in the window hierarchy!" suggests the view is not connected in the Interface Builder or programmatically.
The Deprecated warnings result from Xcode checking the APIs you use in your project settings. If you set the Build Settings' IOS Deployment Target of your Xcode project to iOS 6, then any APIs (such as presentModalViewController and dismissModalViewController) that are marked by Apple as deprecated will be flagged.
Instead use presentViewController:animated:completion: and dismissViewControllerAnimated:completion:, respectively.
[self presentModalViewController:mail animated:YES];
can be replaced by
[self presentViewController:mail animated:YES completion:nil];
and
[self dismissModalViewControllerAnimated:YES];
by
[self dismissViewControllerAnimated:YES completion:nil];
Like Sudha said, use [self presentViewController:mail animated:YES/NO completion:nil];
From iOS6 onwards, presentModalViewController and dismissModalViewController are deprecated, they are used with completion, which would be nil for your case .
Hi you can check MFMailComposerViewController class present or not.
-(void)email{Class emailClass=(NSClassFromString(#"MFMailComposeViewController"));if emailClass!=nil)if ([emailClass canSendMail]{[self displayComposePage];
}
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.
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.
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];