iphoneiosobjective-cuisearchbarabpeoplepickerview

How to hide/Remove the search bar on Contact Picker


I am adding a contact picker in my app, however, I do not want the search functionality.

How to hide/Remove the search bar on Contact Picker (ABPeoplePickerNavigationController)?


Solution

  • 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:@"> "]];
        }
    }
    

    call above method after picker is presented as below:

    -(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];
    }