Jason Machacek
Jason Machacek

Reputation: 994

presentModalViewController not executing?

I'm an experienced software developer (mostly C and C++ in embedded systems, Linux, and Qt for user interfaces). I've recently made the jump to iPhone development and I've run into a confusing issue with UIViewController and presentModalViewController. I'm trying to present a modal ABPeoplePickerNavigationController dialog but it's not appearing.

My main application is controlled by an object called Controller, a subclass of NSObject. I recently added a subclass of UIViewController called AddressBookController (both Controller and AddressBookController are declared in my NIB).

I have this function in Controller which uses an IBOutlet to call a function in AddressBookController (Just a side note, I'm aware that passing 'sender' through is probably not correct--what's the correct way to call a function that's looking for (id)sender as a param?):

- (IBAction)addressPressed:(id)sender
{
    [addressViewController showContactPicker:sender];
}

Here's my interface declaration for AddressBookViewController:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

@interface AddressBookViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate>
{
}

@end

The showContactPicker function in AddressBookController looks like this:

#import "AddressBookViewController.h"

@implementation AddressBookViewController

- (void) showContactPicker:(id)sender
{
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

...

I've verified using the debugger that the [self presentModalViewController:picker animated:YES] is being called, but nothing appears on the screen and code execution just proceeds to [picker release]. Does anyone have any insight as to why this call isn't doing anything? I'm not seeing any error messages, warnings, etc. as I run through this code.

Thanks in advance!

Upvotes: 0

Views: 5361

Answers (1)

Matt Long
Matt Long

Reputation: 24476

You don't specify what nib/xib to use in your init:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];

Change it to:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] initWithNibName@"ABPeoplePickerNavigationController" bundle:nil];

making sure you use whatever your nib file is named, minus the .xib extension.

Upvotes: 1

Related Questions