根據我的要求,如何通過調用方法而不是按鈕點擊打開聯繫人
我需要從聯繫人獲取電子郵件ID。
而且我需要在一個方法的單獨類中編寫代碼。要調用此類,將類集成到我的項目中只需調用該方法即可。
這就是我需要的。
爲此我在ownServices中的代碼是這樣的。
-(NSString *)getSelectedNumberFromContatcs {
ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
peoplePickerController.peoplePickerDelegate = self;
[self presentModalViewController:peoplePickerController animated:NO];
[peoplePickerController release];
return aNSString;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
// NSString *name = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);
return YES;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier {
if (property == kABPersonPhoneProperty) {
ABMultiValueRef emails = ABRecordCopyValue(person, property);
CFStringRef phonenumberselected = ABMultiValueCopyValueAtIndex(emails, identifier);
// CFStringRef emailLabelSelected = ABMultiValueCopyLabelAtIndex(emails, identifier);
// CFStringRef emailLabelSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, identifier));
aNSString = (NSString *)phonenumberselected;
// Return to the main view controller.
[ self dismissModalViewControllerAnimated:YES ];
return NO;
}
return YES ;
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[ self dismissModalViewControllerAnimated:YES ];
}
我打電話給myclassviewcontroller這樣。
- (void)viewDidLoad {
[super viewDidLoad];
ownServices *obj = [[ownServices alloc]init];
[obj getSelectedNumberFromContatcs];
}
但是contatcs viewcontraoller未打開。
但我會像viewconrtroller開了這
-(IBAction)openContacts {
ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
peoplePickerController.peoplePickerDelegate = self;
[self presentModalViewController:peoplePickerController animated:NO];
[peoplePickerController release];
}
然後接觸一個按鈕動作視圖控制器相同的代碼。
我沒有爲什麼視圖控制器沒有通過調用方法打開。
是否可以這樣做。
任何人都可以幫助我。
謝謝你提前。
的可能性,我需要通過調用方法來打開聯繫人,並需要得到選擇email.Code必須在另一個類編寫的this.my子類的UIViewController中繼承只有 – MaheshBabu 2011-06-06 07:17:07
是有任何具體的理由來分離代碼。我可以爲您提供用於提取有電子郵件的聯繫人的代碼。此外,您可以選擇要使用的聯繫人。 – 2011-06-06 08:00:31
是的,我的要求是這樣的 – MaheshBabu 2011-06-06 08:31:52