2010-01-03 13 views
5

पर पता पुस्तिका पता मूल्य निकालें, मैंने निम्नलिखित ट्यूटोरियल का पालन किया है, सिम्युलेटर में यह बहुत अच्छा काम करता है, हालांकि पता लगाने के दौरान मेरे फोन पर, Google मानचित्र लॉन्च करता है, मुझे लगता है कि मैंने तला हुआ है इस पर मेरा दिमाग। मैं इसे NavBarContolloer के संयोजन के रूप में उपयोग कर रहा हूं कोई भी मदद महान होगी।कोको टच ट्यूटोरियल का उपयोग करना: आईफोन ओएस

से लिया: iPhone OS पर निकालें पता पुस्तिका पता मान

कोड यह रहा:: कोको टच ट्यूटोरियल

#import "RootViewController.h" 
#import "SecondViewController.h" 
#import "ThirdViewController.h" 
#import "FourthViewController.h" 


@implementation ThirdViewController 

@synthesize fourthViewController; 
@synthesize firstName; 
@synthesize lastName; 
@synthesize addressLabel; 

-(IBAction)switchPage:(id)sender 
{ 
    if(self.fourthViewController == nil) 
    { 
     FourthViewController *fourthView = [[FourthViewController alloc] 
              initWithNibName:@"FourthView" bundle:[NSBundle mainBundle]]; 
     self.fourthViewController = fourthView; 
     [fourthView release]; 
    } 

    [self.navigationController pushViewController:self.fourthViewController animated:YES]; 
} 

-(IBAction)getContact { 
    // creating the picker 
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; 
    // place the delegate of the picker to the controll 
    picker.peoplePickerDelegate = self; 

    // showing the picker 
    [self presentModalViewController:picker animated:YES]; 
    // releasing 
    [picker release]; 
} 

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker { 
    // assigning control back to the main controller 
    [self dismissModalViewControllerAnimated:YES]; 
} 

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { 

    // setting the first name 
    firstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 

    // setting the last name 
    lastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 

    // setting the street name 
    //ABMultiValueRef street = ABRecordCopyValue(person, kABPersonAddressProperty); 
    // street.text = (NSString *)ABRecordCopyValue(person, kABPersonAddressStreetKey); 

    // setting the number 
    /* 
    this function will set the first number it finds 

    if you do not set a number for a contact it will probably 
    crash 
    */ 
    ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty); 
    number.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0); 

    // remove the controller 
    //[self dismissModalViewControllerAnimated:YES]; 

    return YES; 
} 

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
     shouldContinueAfterSelectingPerson:(ABRecordRef)person 
           property:(ABPropertyID)property 
           identifier:(ABMultiValueIdentifier)identifier { 
    // Only inspect the value if it's an address. 
    if (property == kABPersonAddressProperty) { 
     /* 
     * Set up an ABMultiValue to hold the address values; copy from address 
     * book record. 
     */ 
     ABMultiValueRef multi = ABRecordCopyValue(person, property); 

     // Set up an NSArray and copy the values in. 
     NSArray *theArray = [(id)ABMultiValueCopyArrayOfAllValues(multi) autorelease]; 

     // Figure out which values we want and store the index. 
     const NSUInteger theIndex = ABMultiValueGetIndexForIdentifier(multi, identifier); 

     // Set up an NSDictionary to hold the contents of the array. 
     NSDictionary *theDict = [theArray objectAtIndex:theIndex]; 

     // Set up NSStrings to hold keys and values. First, how many are there? 
     const NSUInteger theCount = [theDict count]; 
     NSString *keys[theCount]; 
     NSString *values[theCount]; 

     // Get the keys and values from the CFDictionary. Note that because 
     // we're using the "GetKeysAndValues" function, you don't need to 
     // release keys or values. It's the "Get Rule" and only applies to 
     // CoreFoundation objects. 
     [theDict getObjects:values andKeys:keys]; 

     // Set the address label's text. 
     NSString *address; 
     address = [NSString stringWithFormat:@"%@, %@, %@, %@ %@", 
        [theDict objectForKey:(NSString *)kABPersonAddressStreetKey], 
        [theDict objectForKey:(NSString *)kABPersonAddressCityKey], 
        [theDict objectForKey:(NSString *)kABPersonAddressStateKey], 
        [theDict objectForKey:(NSString *)kABPersonAddressZIPKey], 
        [theDict objectForKey:(NSString *)kABPersonAddressCountryKey]]; 

     self.addressLabel.text = address; 

     // Memory management. 
     [theDict release]; 

     // Return to the main view controller. 
     [ self dismissModalViewControllerAnimated:YES ]; 
     // return Yes; 
    } 

    // If they didn't pick an address, return YES here to keep going. 
    return YES; 
} 


/* 
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
     // Custom initialization 
    } 
    return self; 
} 
*/ 

/* 
// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 
} 
*/ 

/* 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
} 
*/ 

/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 


@end 
+0

कृपया 4 रिक्त स्थान के साथ प्रत्येक पंक्ति को इंडेंट करके स्वरूपित कोड है, जो हमें आपके कोड को पढ़ने और समझने में मदद करेगा। – Joost

+0

आगे के संदर्भ के लिए, यह http://blog.slaunchaman.com/2009/01/21/cocoa-touch-tutorial-extract-address-book-address-values-on-iphone-os/ –

+0

पर एक टिप्पणी के रूप में शुरू हुआ धन्यवाद, यह मेरा पहला समय है, जोओस्टके, धन्यवाद कि चाल है !! इतनी जल्दी उठने के लिए भी धन्यवाद !! –

उत्तर

6

में

-[ABPeoplePickerNavigationControllerDelegate peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:]

आप में नहीं लौटने के लिए की जरूरत है Google मानचित्र लॉन्च न करने का ऑर्डर करें। रिटर्निंग हाँ डिफ़ॉल्ट कार्रवाई के साथ जारी रहेगा, जो डिवाइस पर Google मानचित्र लॉन्च कर रहा है।

संबंधित मुद्दे