2

我在我的应用程序中添加了一个联系人选择器,但是,我不想要搜索功能。

如何隐藏/删除联系人选择器(ABPeoplePickerNavigationController)上的搜索栏?

4

2 回答 2

2
static BOOL foundSearchBar = NO;
- (void)findSearchBar:(UIView*)parent mark:(NSString*)mark {

    for( UIView* v in [parent subviews] ) {

        //if( foundSearchBar ) return;

        NSLog(@"%@%@",mark,NSStringFromClass([v class]));

        if( [v isKindOfClass:[UISearchBar class]] ) {
            [(UISearchBar*)v  setTintColor:[UIColor blackColor]];
            v.hidden=YES;
//            foundSearchBar = YES;
            break;
        }
        if( [v isKindOfClass:[UITableView class]] ) {
            CGRect temp =v.frame;
            temp.origin.y=temp.origin.y-44;
            temp.size.height=temp.size.height+44;
            v.frame=temp;
            //foundSearchBar = YES;
            break;
        }
        [self findSearchBar:v mark:[mark stringByAppendingString:@"> "]];
    }
}

在选择器出现后调用上述方法如下:

-(void)showPeoplePickerController
{
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    picker.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    // Display only a person's phone, email, and birthdate
    NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], 
                                [NSNumber numberWithInt:kABPersonEmailProperty],
                                [NSNumber numberWithInt:kABPersonBirthdayProperty],[NSNumber numberWithInt:kABPersonAddressProperty],nil];

    picker.displayedProperties = displayedItems;
    // Show the picker
    [self presentViewController:picker animated:YES completion:nil];
    [self findSearchBar:[picker view] mark:@"> "];

    [picker release];
}
于 2013-06-17T06:31:35.007 回答
0
-(void)showAddressBook {
    ABPeoplePickerNavigationController *addressBook = [[ABPeoplePickerNavigationController alloc] init];
    [addressBook setPeoplePickerDelegate:self];
    addressBook.delegate = self;
    addressBook.navigationBar.topItem.title = @"iPhone Contacts";
    UIView *view = addressBook.topViewController.view;
    for (UIView *v in view.subviews) {
        if ( [v isKindOfClass:[UITableView class]] ) {
            CGRect temp = v.frame;
            temp.origin.y = temp.origin.y - 44;
            temp.size.height = temp.size.height + 44;
            v.frame = temp;
        }
    }
    [addressBook release];
}

- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ([navigationController isKindOfClass:[ABPeoplePickerNavigationController class]]) {
        UISearchDisplayController *searchDisplayController = navigationController.topViewController.searchDisplayController;
        [searchDisplayController.searchBar setHidden:YES];
    }
}
于 2014-07-01T13:27:46.663 回答