iOS 搜索框

来源:互联网 发布:时代网络大厦 美食 编辑:程序博客网 时间:2024/05/21 22:30


创建在tableview上面的搜索框


table = [[UITableViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height)style:UITableViewStylePlain];

    

    table.delegate =self;

    table.dataSource =self;

    table.tableFooterView = [[UIViewalloc] initWithFrame:CGRectZero];

    //****************

    table.allowsMultipleSelectionDuringEditing =YES;

    [self.viewaddSubview:table];


//    创建搜索框

    UISearchBar * searchB = [[UISearchBaralloc]initWithFrame:CGRectMake(0,0, 0, 80)];

//    设置提示文字

    searchB.placeholder = @"请输入文字";

//    设置搜索框的样式

    searchB.searchBarStyle =UISearchBarStyleDefault;

//    是否显示取消按钮

    searchB.showsBookmarkButton =YES;

//  建立代理关系

    searchB.delegate = self;

    

    

    displayController = [[UISearchDisplayControlleralloc]initWithSearchBar:searchBcontentsController:self];

    displayController.searchResultsDelegate =self;

    displayController.searchResultsDataSource =self;

    displayController.searchResultsTableView.tableFooterView = [[UIViewalloc]initWithFrame:CGRectZero];

    

    table.tableHeaderView = searchB;

搜索代理方法

- (NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView{

    returnsearchArray;

}





0 0
原创粉丝点击