iphone - 如何隐藏/删除联系人选择器上的搜索栏

标签 iphone ios objective-c uisearchbar abpeoplepickerview

我正在我的应用中添加联系人选择器,但是,我不需要搜索功能。

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

最佳答案

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

关于iphone - 如何隐藏/删除联系人选择器上的搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17141210/

相关文章:

iphone - 在 .htaccess/apache 中检测 iPhone 浏览器并重定向到 iPhone 站点

iphone - 我如何为我的 iPhone 应用程序集成谷歌地图 API?

iphone - 整个应用程序中的单个动画 UIImageView 背景

ios - "fb://"url scheme - 官方与否?

objective-c - Xcode 中的 NSObject 描述和自定义摘要

ios - 调整 UITextfield 宽度

ios - 3D Touch 静态快捷键

ios - swift 2 : Change navigation title on a view related to a Tab Bar Controller

ios - 以编程方式将 AutoLayout 用于搜索栏和 UITableView

ios - BLE后台重连