I have an iPhone app which hides the status bar when run. After launching a MFMessageComposeViewController and dismissing it (after either send or cancel) all my previously drawn elements are shifted down 20px. This is clearly to do with the status bar showing when the MFMessageComposeViewController is presented.
Can I either stop this happening or fix it in my (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result method to undo the change?
Thanks :)
OK, turned out I needed to set:
self.wantsFullScreenLayout = YES;
in my view controller. this fixed it. perhaps it's useful to someone else.
After I launch the modal view picker is when I remove the status bar.
You may need to set it to NO when you return.
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.wantsFullScreenLayout = NO;
NSString * currentString = nil;
currentString = [[NSString alloc] initWithFormat:#"Just a Test (iPhone/iPod/iPad)." ];
picker.body = currentString;
[self presentModalViewController:picker animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Related
I've set up a void method which is called from another class if the user touches the button.
However, I got this error with "whose view is not in window hierarchy" and then I found this: whose view is not in the window hierarchy. I just want to call the method below but I got this error and it doesn't show me the navigatoncontroller. It says Warning: Attempt to present <UINavigationController: 0xae34f10> on <ViewController: 0xae1f200> whose view is not in the window hierarchy!
I don't know if this is possible to call the method from the viewDidAppear or from somewhere that it only works if the button was tapped on the other view before. If I call a NSLog in the method it shows me the NSLog in the output. Only the presenting of the navController doesn't seems to work. I would be happy if someone could help me with this.
My method:
- (void) launchGalleryView
{
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
// Set browser options.
browser.wantsFullScreenLayout = YES;
browser.displayActionButton = NO;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];
NSMutableArray *photos = [[NSMutableArray alloc] init];
MWPhoto *photo;
photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:#"calculator" ofType:#"jpg"]];
photo.caption = #"The calculator is soo beauteful...";
[photos addObject:photo];
self.photos = photos;
[self presentModalViewController:navController animated:YES];
}
Just forgot to say: The MWPhotoprowser is a class which actually does't matter.
Thanks in advance.
The error message is pretty clear -- you're trying to present the controller from this class, but the class that has the button you pressed is the one whose view is in the view hierarchy. You either need to present it from the class with the button, or get back to this class however you're doing that, and then call it after viewDidAppear.
i checked your project.. wasn't able to sort out the proper issue..
but i tried a hack and it worked..
replace this line with
[self presentModalViewController:navController animated:YES];
this
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentModalViewController:navController animated:YES];
I'm using the following code to show in-app sms. My app don't have a status bar. (I'm using 320x480 pixels screen in portrait view)
if ([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController* msgController = [[MFMessageComposeViewController alloc] init];
msgController.recipients = [NSArray arrayWithObject:self.globalSMS];
msgController.messageComposeDelegate = self;
[self presentModalViewController:msgController animated:YES];
[msgController release];
}
This is working good to display the message view controller. (But status bar comes back, which is not necessary for me to show)
But the problem is that when I click "Cancel" or "Send", after going back to application, I am seeing white space on the top (in position of status bar) of the screen. And status bar is hidden.
Why is it happening when my status bar is set as hidden in app delegate. How to get rid of white space after showing the in-app sms view.
Hide the status bar after you modal presented the message controller. Something like this:
controller.wantsFullScreenLayout = NO;
[self presentModalViewController:controller animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Also Answered here: MFMessageComposeViewController not properly displayed
I found the answer. We've to set in view controller's viewDidLoad method:
self.wantsFullScreenLayout = YES;
The issue is in portrait view. From what I am seeing if the MFMessageComposeViewController loads in landscape the space isn't there. Then if the orientation changes to portrait the layout is corrected and the space isn't present in portrait.
Note When in landscape the MFMessageComposeViewController is presented by sliding from left to right. I believe that the way the view is presented holds to key to fixing the issue.
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = #"MessageText!!!";
controller.recipients = [NSArray arrayWithObjects:#"123"];
controller.messageComposeDelegate = self;
controller.wantsFullScreenLayout = YES;
[self presentModalViewController:controller animated:YES];
}
I want to launch the contacts list people picker as soon as my app has finished loading, but the obvious thing doesn't seem to be working.
- (void)viewDidLoad {
name.hidden = NO;
name.text = #"ViewDidLoad";
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
The UILabel named "name" is getting set appropriately, but the people picker doesn't show.
I've got a button hooked up to instantiate the people picker when it's pressed, and that works fine.
Any suggestions?
Thanks!
viewDidLoad is not a good place for showing anything since your view is still not ready to be shown. Call it in viewWillAppear.
I have this working but I don't think it is working correctly so I just wanted to get your feedback. I am trying to display a screen that has two buttons - one that takes you to a login screen and the the allows you to register.
II am testing in the appDelegate if they are logged in and if they aren't I am showing the signLogIN view.
signLogIN = [[LoginOrSignUPViewController alloc] init];
signLogIN.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
signLogIN.tabBarController = mainAPPTabBarController;
signLogIN.mainWindow = window;
[window addSubview:[signLogIN view]];
//[signLogIN release];
(I release in the appDelegate dealloc - if I release here it blows up when they select to either login or register).
I did try doing:-
[mainAPPTabBarController presentModalViewController:signLogIN animated:NO];
But it made no difference.
Curiously I can see that the dealloc in LoginOrSignUPViewController is called straight away - why is that? I can't tell where it is being called from.
From LoginOrSignUPViewController I am then displaying the login screen by doing:-
[self retainCount] = 1
LoginViewController *logINVC = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
logINVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
logINVC.delegate = self;
logINVC.tabBarController = self.tabBarController;
[self presentModalViewController:logINVC animated:YES];
[logINVC release];
now [self retainCount] = 3 = why did it go to three????
As you can see there is a delegate that calls back to the signLogIn view to close the view as follows:-
[self retainCount] = 3
[mainWindow bringSubviewToFront:tabBarController.view];
tabBarController.selectedIndex = 0;
[self.view removeFromSuperview];
[self dismissModalViewControllerAnimated:NO];
[self release];
[self retainCount] = 3 -- still 3 it never goes away
So here is my main problem LoginOrSignUPViewController never goes away it just sits behind my main view. The only line that makes any difference is the [mainWindow bringSubViewToFront. Does anyone have any ideas as to how to make the LoginOrSignUPViewController disappear?
Thanks very much
Cheryl
Have you tried this in your view controller's viewDidLoad:
LoginOrSignUPViewController *signLogIN = [[LoginOrSignUPViewController alloc] init];
[self presentModalViewController:signLogIN animated:NO];
[signLogIn release];
I have an app, inside that an UIViewController is attached on the UIWindow.
on the view of UIViewController, i have added a button and a uiview_1 of size 100x80.
this uiview_1 contains another uiview_2 as subview of same size and this uiview_2 contains a UIImageView or a UIlable at runtime (both UIImageView and UIlable are userinteraction enabled)
now on the touch/click of UIImageView, i want to show a new view using presentModalViewController, the problem is the view is shown and using back button on the navigation bar i come to the previous/main screen.
here the problem come in picture, now i am unable to touch the button or the UIImageView.
both are not responding, but app is not crashed and nor frozen.
what is wrong in that?
Plz help in this...
----- EDIT:
Approach First:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
UIViewController *pushController = [[UIViewController alloc] init];
UIWindow *win = [[UIApplication sharedApplication] keyWindow];
[win addSubview:pushController.view];
[pushController presentModalViewController:viewNavController animated:YES];
In the swvController i have back button that calls the dismissModelViewController on click >> result is the Main screen ctrls are not responding to touch – sandy 3 hours ago
Second approach:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
UIViewController *pushController = [[UIViewController alloc] init];
[self addSubview:pushController.view];
[pushController presentModalViewController:viewNavController animated:YES];
In the swvController i have back button that calls the dismissModelViewController on click >> result is the swvController's back button on navbar is not responding – sandy 3 hours ago
3rd approach:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
SampleAppAppDelegate *appdel = [[UIApplication sharedApplication] delegate]; [appdel.viewController presentModalViewController:viewNavController animated:YES];
>> result is working fine, but the problem is i dont want to use SampleAppAppDelegate,i want to give my small Uiview (100x80) as a ctrl to other person , where my ctrl will not able to get the AppDelegate of thet app at run time. – sandy 3 hours ago
Call this method when you want to present the modal view controller:
- (IBAction)showInfo {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Add this method to your self:
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
Use a toolbar or other button and connect it to this method in your modal view controller:
- (IBAction)done {
[self.delegate flipsideViewControllerDidFinish:self];
}
All code comes from Apple.
How did you handled click/touch on UIImageView? TouchesBegan/Ended?
Try putting some logs (NSLog) and run your app in debug mode (put some breakpoints) to see if control reaches your action method...
Also, when you do presentModalViewController, you do not need to POP out with back button on navigation bar... you only need to dismissModelViewController to hide it.