开发者

iphone ABNewPersonViewController seems to not be responding to delegate

I'm halfway through implementing a very basic 'Add Contact' Button. I am calling the 'Add View' using the code (via a linked UIButton, that works) :

- (IBAction)showAddContact {
 NSLog(@"Hit showAddContact");

 ABNewPersonViewController *newPersonViewController = [[ABNewPersonViewController alloc] init];

 addContactNavController = [[UINavigationController alloc] initWithRootVi开发者_如何学CewController:newPersonViewController];
 [self presentModalViewController:addContactNavController animated:YES];
}

and then I have also set the delegate resonse of:

- (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person {
  NSLog(@"Hit newPersonViewController");
 //ABContact *contact = [ABContact contactWithRecord:person]; 
 [self.navigationController popViewControllerAnimated:YES];
}

in my header I have set:

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

@interface test2ViewController : UIViewController <ABNewPersonViewControllerDelegate> {
UINavigationController* addContactNavController;
}

- (IBAction)showAddContact;

@end

I have added the frameworks Addressbook and AddressBookUI.

The add dialog box comes up as expected, I can edit the contact, but I am not able to remove the modal View Controller from the view.

I have even duplicated the problem in a simple test project available here:link text

What am I missing?, I bet it is something extremely simple. Thanks @norskben


Couple of problems:

You should release the ABNewPersonViewController after presenting it.

You present the ABNewPersonViewController as a modal dialog with presentModalViewController: but you remove it from the screen as if it was pushed on a UINavigationController with popViewControllerAnimated:. Instead you should either push and pop, or present and dismiss. (If you don't know what this means, read a little int he View Controller documentation)

Even though you implement the ABNewPersonViewControllerDelegate protocol, you never set the delegate property of the ABNewPersonViewController.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜