Apple's controllers not presenting properly in iOS7 - ios

In my iOS app i present standerd controllers MFMessageComposeViewController and UIImagePickerController.
But they both presenting with strange navigation bar.
How can i fix this problem?
UPD code for presenting controllers
UIImagePickerController:
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = sourceType;
cameraUI.allowsEditing = YES;
cameraUI.delegate = self;
[self presentViewController:cameraUI animated:YES completion:nil];
MFMessageComposeViewController:
MFMessageComposeViewController *messageViewController = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]) {
messageViewController.view.backgroundColor = [UIColor whiteColor];
messageViewController.messageComposeDelegate = self;
recipient= [NSStringMask maskString:recipient withPattern:#"\\+(\\d{1}) \\((\\d{3})\\) (\\d{3})-(\\d{2})-(\\d{2})"];
messageViewController.recipients = #[recipient];
messageViewController.body = body;
[self presentViewController:messageViewController animated:YES completion:nil];
}

In iOS 7, the status bar and the navigation is translucent by default. To make the view act 'normal' like in iOS 6. you need to add this to the controller you are presenting.
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
If you want to read up more about changes in views. Check out this post. I find it a nice quick overview whats changed.
http://www.brianjcoleman.com/ios7-weve-got-a-problem/

See this question. I used the second answer, though I suspect the first would work for me also.

Related

UIPopoverPresentationController is showing full screen modal on iPhone

On iPad UIPopoverPresentationController working fine but on iPhone it is always showing full window modal popup. i am using following code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MySecondViewController *contentVC = [storyboard instantiateViewControllerWithIdentifier:#"Pop"];
contentVC.modalPresentationStyle = UINavigationControllerOperationPop; // 13
UIPopoverPresentationController *popPC = contentVC.popoverPresentationController; // 14
contentVC.popoverPresentationController.sourceRect =CGRectMake(100, 130, 280, 230);
self.navigationController.preferredContentSize = CGSizeMake(200, self.parentViewController.childViewControllers.lastObject.preferredContentSize.height-100);
//self.showPop.frame; // 15
contentVC.popoverPresentationController.sourceView =
self.showPop; // 16
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; // 17
popPC.delegate = self; //18
[self presentViewController:contentVC animated:YES completion:nil];
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
In ViewController.h Firstly make a property of UIPopoverPresenatationController.
#property(nonatomic,retain)UIPopoverPresentationController *dateTimePopover8;
Then to show PopOverPresentationcontroller
UINavigationController *destNav = [[UINavigationController alloc] initWithRootViewController:dateVC];/*Here dateVC is controller you want to show in popover*/
dateVC.preferredContentSize = CGSizeMake(280,200);
destNav.modalPresentationStyle = UIModalPresentationPopover;
_dateTimePopover8 = destNav.popoverPresentationController;
_dateTimePopover8.delegate = self;
_dateTimePopover8.sourceView = self.view;
_dateTimePopover8.sourceRect = [sender frame];
destNav.modalPresentationStyle = UIModalPresentationPopover;
destNav.navigationBarHidden = YES;
[self presentViewController:destNav animated:YES completion:nil];
You must have noticed that we are presenting View Controller instead of presenting popOver.So we have to hide this in new way also.It hides automatically when we click on screen.
-(void)hideIOS8PopOver
{
[self dismissViewControllerAnimated:YES completion:nil];
}
We have to implement the delegate of UIPopoverPresenatationController in implementation file.Write below delegate method in implementation file.
- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController: (UIPresentationController * ) controller {
return UIModalPresentationNone;
}
Popover controllers are for use exclusively on iPad devices.
Edit: As stated by Soberman, since iOS 8 it is possible to present popovers on iPhone using public APIs, so this answer is probably not relevant anymore.
As stated in Apple's documentation on UIPopoverController:
Popover controllers are for use exclusively on iPad devices.
So there is no way to use this class in iPhone application unfortunately. But there are a couple of custom third-party implementations of the functionality provided by UIPopoverController which add iPhone support and more. See https://github.com/50pixels/FPPopover for example.
Edit: There also is another highly customizable popover implementation for both iPhone/iPad worth checking out: https://github.com/nicolaschengdev/WYPopoverController.

UIPopoverController alternative on iphone devices

I have been searching for almost 2 hours on how to implement UIPopoverController in swift language, at the end, i found out that this api are exclusive for iPad devices only.
How will i be able to make a drop down list on iPhone devices?
please someone help me, at lease with the name of the api so that i know what to search for
You can you third party libraries for that:
FPPopover
WEPopover
or if you don't need iOS 7 support you can use iOS 8 new API which answered in this question
UIPopoverPresentationController on iOS 8 iPhone
i depends on your needs. You can show UIPickerView, present an action sheet or segue to another VC and then go back - these are standard ways.
#property(nonatomic,retain) UIPopoverPresentationController *popoverPresentationController;
- (IBAction)showPopover:(id)sender {
UIViewController *popoverViewController = [[UIViewController alloc] initWithNibName:#"NameViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:popoverViewController];
popoverViewController.preferredContentSize = CGSizeMake(280, 200);
navigationController.modalPresentationStyle = UIModalPresentationPopover;
_popoverPresentationController = navigationController.popoverPresentationController;
_popoverPresentationController.delegate = self;
_popoverPresentationController.sourceView = self.view;
_popoverPresentationController.sourceRect = [sender frame];
navigationController.modalPresentationStyle = UIModalPresentationPopover;
navigationController.navigationBarHidden = YES;
[_viewController presentViewController:navigationController animated:YES completion:nil];
}

Custom UIView like UIPopoverController

Would like to learn how UIPopoverController style UIViews are created.Below is the image from Storehouse iOS app running on iPhone(apple design award winner) , you can see the view moreover looks like UIPopoverController ,any help is greatly appreciated.
You can handle your own custom view check out this How to Place custom view in IOS over another view
You can use this
- (IBAction)ContinueToPayment:(id)sender {
PayByVC *Newpage = [[PayByVC alloc] initWithNibName:#"PayByVC" bundle:nil];
Newpage.checkOutInfoDict=checkOutDict;
Newpage.modalPresentationStyle = UIModalPresentationOverCurrentContext;
Newpage.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
Newpage.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.4];
Newpage.delegate = self;
[self presentViewController:Newpage animated:YES completion:nil];
}

MFMessageComposeViewController bar transparent

I'm trying to present a MFMessageComposeViewController modally.
MFMessageComposeViewController *controller =[[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"Welcome to my app!";
controller.recipients = [NSArray arrayWithObjects:#"99999999", nil];
controller.messageComposeDelegate = self;
[self presentViewController:controller
animated:TRUE
completion:nil];
}
The navigation bar of the MFMessageComposeViewController appears transparent.
The controller is appearing like this:
Any ideas how to fix this?
Thanks,
Daniel
You've made changes to the navigation bar using the appearance proxy. Either revert those changes, or override them directly on MFMessageComposeViewController's navigation bar.

UIPopovercontroller dealloc reached while popover is still visible

I assure you that I did look for an answer in SO for my question but none of them were helpful. Here I got a simple code that should present a UIImagePickerController within a UIPopoverController:
-(void)takePicture:(id)sender{
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing=YES;
UIPopoverController *poc=[[UIPopoverController alloc]
initWithContentViewController:picker];
[poc presentPopoverFromBarButtonItem:bbItem
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:NO];
}
Now, even from the first time I get [UIPopoveController dealloc] reached while... error and the program crashes. I'm not doing any retain,relase or autoreleases as per ARC. Is there any special consideration with UIPopoverControllers when benefitting from ARC?
UIPopoverControllers should always be held in an instance variable. It is a good practice to create a strong property for it.
UPDATE:
As of iOS 8 you should be using UIPopoverPresentationController. Then you don't need to keep a reference to the popover because it is managed by the presentation controller.
Code example (works both on iPhone and iPad):
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = YES;
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController* popoverPC = picker.popoverPresentationController;
popoverPC.barButtonItem = bbItem;
popoverPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:picker animated:YES completion:nil];
When the function exits there are no other reference to the popover controller, so it's deallocated too early.
Try adding it as a member of your class instead.
Tim
Adding what #phix23 answered, create *poc property like this:
#property (nonatomic, retain) IBOutlet UIPopoverController *poc;
and then change
UIPopoverController *poc = [[UIPopoverController alloc]
initWithContentViewController:picker];
for
self.poc = [[UIPopoverController alloc]
initWithContentViewController:picker];

Resources