重粒子的运行轨迹

Compiling ...
baryon.cpp
baryon.cpp(1) : warning C0000: all glory is fleeing

导航

[iPhone]如何在Tab Bar Controller里面使用ABPersonViewController?

 如果你想将ABPersonViewController嵌入一个Tab Bar Controller里作为一个Tab,就像下图,该如何作呢?

 

 

Step By Step

1:制作xib的时候,不要在相应的tab里加入view controll,如下图:

 

 2,创建自己的NavigationController,继承自UINavigationController,加入ABPersonViewControllerDelegateprotocol

 

@interface ProfileNavigationController : UINavigationController<ABPersonViewControllerDelegate> {
    

}


 3,在自己的NavigationController里面相应-(void)awakeFromNib,这个方法在xib被调入内存的时候,会被执行,在其中调用initWithRootViewController,就可以将需要的ViewController显示出来。

 

 

-(void)awakeFromNib


-(void)awakeFromNib
{
    NSLog(
@"bundleLoader waked");
    
// Fetch the address book 
    ABAddressBookRef addressBook = ABAddressBookCreate();
    
// Search for the person named "Appleseed" in the address book
    CFArrayRef people = ABAddressBookCopyPeopleWithName(addressBook, CFSTR("Appleseed"));
    
// Display "Appleseed" information if found in the address book 
    if ((people != nil) && (CFArrayGetCount(people) > 0))
    {
        ABRecordRef person 
= CFArrayGetValueAtIndex(people, 0);
        ABPersonViewController personPicker 
= [[[ProfileViewController alloc] init] autorelease];
        personPicker.personViewDelegate 
= self;
        personPicker.displayedPerson 
= person;
        
// Allow users to edit the person’s information
        personPicker.allowsEditing = YES;
        
        [self initWithRootViewController:personPicker];
    }
    
else 
    {
        
// Show an alert if "Appleseed" is not in Contacts
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                        message:
@"Could not find Appleseed in the Contacts application" 
                                                       
delegate:nil 
                                              cancelButtonTitle:
@"Cancel" 
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    CFRelease(addressBook);
    CFRelease(people);
}


 

posted on 2010-04-30 13:47  重粒子  阅读(2173)  评论(0编辑  收藏  举报