Launch People Picker in viewDidLoad? - iphone

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.

Related

add eventViewController not showing anything

I'm currently working on a agenda part of an app. I managed to show all my events and also go to the details from it and edit it. But when I want to add an event it shows me an empty view. I should mention that I have a custom datasource for my calendar.
To edit an Event I just do this in my ViewController.
EKEventViewController *vc = [[EKEventViewController alloc] init];
vc.event = [dataSource eventAtIndexPath:indexPath];
vc.allowsEditing = YES;
[calendar.navigationController pushViewController:vc animated:YES];
This is showing me the correct VC with the correct event.
Now this is my code for adding a event.
EKEventEditViewController *addController = [[EKEventEditViewController alloc]init];
// set the addController's event store to the current event store.
addController.eventStore = self.eventStore;
addController.editing = YES;
// present EventsAddViewController as a modal view controller
[self presentModalViewController:addController animated:YES];
addController.editViewDelegate = dataSource;
But when I run it I get an empty viewController. Can anybody help me with this?
Kind regards.
I'm guessing that you didn't create the event store. I looked at Apple's demo program, and I could eliminate all but 4 lines, and still get that edit controller to show up:
#import <EventKitUI/EventKitUI.h>
#implementation ViewController
-(IBAction)doStuff:(id)sender {
EKEventEditViewController *addController = [[EKEventEditViewController alloc]init];
addController.eventStore = [[EKEventStore alloc] init];
[self presentViewController:addController animated:YES completion:nil];
}

ABPeoplePicker: Reset Custom Navigationbar Appearance

I am using a custom appearance of my UINavigationBar, the UIBarBattunItems and the BackButton. Additionally, I am using Apple's ABPeoplePicker to let the user choose from some contacts. My problem is that I would like to reset the appearance to the default appearance but only while the people picker is presented modally.
Does anyone know how to achieve this?
I am presenting my people picker in the following way.
//showing people picker do identify owner of the certificate
ABPeoplePickerNavigationController* picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
Thanks in advance!
Try adding the following code before the present picker.
picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
picker.modalPresentationStyle = UIModalPresentationOverCurrentContext;

How to display NavigationController-background within a UIPopoverController on iPhone

How can i display the background of the NavigationController (including title/buttons) in my UIPopovercontroller on the iPhone?
At the moment it looks like that:
In my PopoverView-ViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.hidden = NO;
self.navigationController.navigationBarHidden = NO;
self.navigationItem.title = #"self.navigationItem.title";
}
When calling Popover:
InfoView *iv = [[InfoView alloc] initWithNibName:#"InfoView" bundle:nil];
UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];
self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
[self.pop setDelegate:self];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];
It should look like this:
At first UINavigationController doesn't have own background, it shows background of content view controller. If you can show popover with navigation controller successfully, then check your InfoView. Does it's view has some background?
Second, I tried to execute your code multiple times in different configurations on iPhone, but always have received error
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[UIPopoverController
initWithContentViewController:] called when not running under
UIUserInterfaceIdiomPad.
And that was not surprise for me. Even if you could make it work, then Apple may reject your application.
2.1 Apps that crash will be rejected - Just test your code on several devices and see result.
your code
InfoView *iv = [[InfoView alloc] initWithNibName:#"InfoView" bundle:nil];
UINavigationController *uc = [[UINavigationController alloc] initWithRootViewController:iv];
self.pop = [[UIPopoverController alloc] initWithContentViewController:uc];
[self.pop setDelegate:self];
[self.pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];
is perfect just hide the default navigation controller and add a navigationBar in the XIB of InfoView.xib and write the cancelButtonAction there to perform the dismissal of the view or the detail of the tableview selection. It Works fine, Please check the image i have done the same way, and believe me it works fine.
Add this to your code before the line [self.pop presentPopoverFromBarButtonItem:se..:
uc.modalPresentationStyle = UIModalPresentationCurrentContext;
See the documentation for the modalPresentationStyle property.
I think you'll need to paste in more of the code for your InfoView controller, as I suspect that's where the problem is.
Have you tried setting up your background view as a class?
[pop setPopoverBackgroundViewClass:bgView];

MFMessageComposeViewController pushes my view down 20px. Why? How to fix?

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

Blank MFMailComposeViewController the second time it is presented?

I got a strange problem with MFMailComposeViewController.
The first time it is displayed using presentModalViewController:animated, everything works perfectly.
The second time it is blank, with nothing on screen except for the navigation bar, the Cancel & Send button.
I have already set the mailComposeDelegate correctly, and dismiss the view controller properly in the delegate.
Any idea why that happens?
EDIT: The code is:
- (void)viewDidLoad {
mailComposeViewController = [[MFMailComposeViewController alloc] init];
[mailComposeViewController setMailComposeDelegate:self];
}
- (void)dealloc {
[mailComposeViewController release];
}
- (void)mail {
[self presentModalViewController:mailComposeViewController animated:YES];
}
Okay, I somehow solved my problem. I moved my MFMailComposeViewController's init & release code from viewDidLoad & dealloc, respectively to exactly where I choose to present the view controller.
Then, it worked.