欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

iOS搜索條使用詳解

    在ios開發(fā)中搜索條的使用挺常見的,不過之前一直沒用到也沒細細研究,最近做外包項目的時候剛好用到,在這里記錄一下使用的過程,只要理解了原理,其實還是比較簡單的!上傳的圖片有點大,剛好可以看清楚它的使用效果!iOS 搜索條使用詳解

站在用戶的角度思考問題,與客戶深入溝通,找到播州網(wǎng)站設計與播州網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設計與互聯(lián)網(wǎng)技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站建設、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、申請域名、虛擬主機、企業(yè)郵箱。業(yè)務覆蓋播州地區(qū)。

 我喜歡一步步的解析控件使用過程,其實真正的用心做一件事情是很享受的,雖然現(xiàn)在的社會都很注重效率和回報,這也是中國這種社會環(huán)境下難出大師級的人物的很重要的一個因素。扯得有點遠了,只是希望國內開發(fā)者不要太急功近利,熟練應用本不是難事,一點點積累就好。下面開始搜索條 

UISearchBar 和 UISearchDisplayController 的使用介紹。

 第一步:添加UISearchBarDelegate,UISearchDisplayDelegate 委托

 第二步:就是UISearchBar 和UISearchDisplayController的使用

//搜索框

    self.searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(10, 15, self.view.bounds.size.width-20, 45)]autorelease];

    searchBar.placeholder=@"輸入城市名或拼音";

    searchBar.delegate = self;

    searchBar.backgroundColor=[UIColor clearColor];

    searchBar.backgroundImage=[UIImage p_w_picpathNamed:@"搜索背景"];

    searchBar.keyboardType=UIKeyboardTypeDefault;

    myTableView.tableHeaderView = searchBar;

    searchBar.autocorrectionType = UITextAutocorrectionTypeNo;

    searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;

    

    

    self.searchdispalyCtrl = [[[UISearchDisplayController  alloc] initWithSearchBar:searchBar contentsController:self]autorelease];

    //設置取消按鈕文字顏色

    searchdispalyCtrl.searchBar.tintColor=BB_Yanzheng_Color;

    //search dispalyCtrl.active = NO;

    //[searchdispalyCtrl.searchResultsTableView setHidden:NO];

    searchdispalyCtrl.delegate = self;

    searchdispalyCtrl.searchResultsDelegate=self;

    searchdispalyCtrl.searchResultsDataSource = self;

 這里面有兩個點需要注意一下,一個是 myTableView.tableHeaderView = searchBar;這里是將searchbar放在對應列表的第一個section之中,而且section的高度不用設置,當然可以通過addsubview添加這種方式會產(chǎn)生一種移位,建議默認的方式比較好些!另一點是UISearchDisplayController是對searchbar的進一步封裝,里面的東西確實簡化了好多,可以采用這種方法設置取消按鈕文本的顏色searchdispalyCtrl.searchBar.tintColor=BB_Yanzheng_Color;

 第三步:相關委托的使用

我們通過實驗發(fā)現(xiàn)點擊searchbar的輸入框會彈出一個獨立的tableview視圖,并顯示一個取消按鈕,搜索的數(shù)據(jù)顯示在這個獨立的視圖列表中。而這個視圖列表和普通的列表用法一樣,需要設置

 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

 

{

 

    if (tableView == self.searchDisplayController.searchResultsTableView)

 

    {

 

        return 1;

 

    }

 

    else

 

    {

 

        return 26;

 

    }

 

}

 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

 

{

 

    if (tableView == self.searchDisplayController.searchResultsTableView)

 

    {

 

        NSLog(@"我去:%@",searchResult);

 

        return [searchResult count];

 

    }

 

    else

 

    {

 

        if (section==0||section==1||section==2||section==3)

 

        {

 

            return 1;

 

        }

 

        if (isZiMu)

 

        {

 

            NSLog(@"zimugeshu:%@,%d",[zimuList objectAtIndex:section-4],[[cityGroupList objectForKey:[zimuList objectAtIndex:section-4]]count]);

 

            return [[cityGroupList objectForKey:[zimuList objectAtIndex:section-4]]count];

 

        }

 

       

 

        /*

 

        char mychar='a';

 

        //當前字母

 

        NSString *zimu=[NSString stringWithFormat:@"%c",mychar-32];

 

        

 

        //NSString *zimu=[NSString stringWithFormat:@"%c",c];

 

        if (![zimu isEqualToString:@"i"]&&![zimu isEqualToString:@"o"]&&![zimu isEqualToString:@"u"]&&![zimu isEqualToString:@"v"])

 

        {

 

            NSLog(@"zimugeshu:%@,%d",zimu,[[cityGroupList objectForKey:zimu]count]);

 

            return [[cityGroupList objectForKey:[zimuList objectAtIndex:section-4]]count];

 

            

 

        }*/

 

       

 

        return 0;

 

        

 

    }

 

    

 

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (tableView == self.searchDisplayController.searchResultsTableView)

    {

        return 45;

    }

    if (indexPath.section==0)

    {

        return 0;

    }

    if (indexPath.section==1||indexPath.section==2)

    {

        return 73;

    }

    if (indexPath.section==3)

    {

        //超過的話固定顯示203

        if (17+([remenCityList count]/3+1)*47+18<=223)

        {

            if ([remenCityList count]!=0&&[remenCityList count]%3==0)

            {

                return 17+([remenCityList count]/3)*47;

            }

            return 17+([remenCityList count]/3+1)*47;

        }

        return 223;

    }

    return 45;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    if (tableView == self.searchDisplayController.searchResultsTableView)

    {

        return 0;

    }

    if (section!=0)

    {

        return 32;

    }

    return 0.01f;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    if (tableView == self.searchDisplayController.searchResultsTableView)

    {

        return 0.01;

    }

    return 0.01f;

}

這些個基本的高度和行數(shù) 模塊信息,當然列表的顯示更是必不可少

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (tableView == self.searchDisplayController.searchResultsTableView)

    {

        static NSString *simpleTableIdentifier = @"RecipeCell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

        if (cell == nil)

        {

            cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]autorelease];

        }

        else

        {

            for(UIView *view in cell.contentView.subviews)

            {

                [view removeFromSuperview];

            }

        }

        //cell.textLabel.text = [searchResult objectAtIndex:indexPath.row];

        //[cell.textLabel setTextColor:BB_Red_Color];

        //NSLog(@"zheli:%@,%d,%@",[searchResult objectAtIndex:indexPath.row],indexPath.row,self.searchDisplayController.searchResultsTableView);

        

        //城市名稱

        UILabel *labLeft = [[[UILabel alloc]init]autorelease];

        labLeft.backgroundColor = [UIColor clearColor];

        labLeft.textAlignment = NSTextAlignmentLeft;

        labLeft.font = [UIFont systemFontOfSize:15];

        labLeft.textColor = [UIColor blackColor];

        labLeft.frame = CGRectMake(15, 15, 200, 15);

        labLeft.text=[searchResult objectAtIndex:indexPath.row];

        [cell.contentView addSubview:labLeft];

        return cell;

    }

}

上面列出的只是顯示信息,真正數(shù)據(jù)的搜索要依賴于下面的委托方法實現(xiàn)

 

#pragma mark - UISearchDisplayDelegate

 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString

 

{

 

    [self filterContentForSearchText:searchString

 

                               scope:[self.searchBar scopeButtonTitles][self.searchBar.selectedScopeButtonIndex]];

 

    

 

    NSLog(@"woshuoba:%@,%@,%d,%@",searchString,self.searchBar.scopeButtonTitles,self.searchBar.selectedScopeButtonIndex,[self.searchBar scopeButtonTitles][self.searchBar.selectedScopeButtonIndex]);

 

    return YES;

 

}

 

-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope

 

{

 

    NSMutableArray *tempResults = [[[NSMutableArray array]init]autorelease];

 

    NSMutableArray *tempResultsId = [[[NSMutableArray array]init]autorelease];

 

    [tempResults removeAllObjects];

 

    [tempResultsId removeAllObjects];

 

 

 

    NSUInteger searchOptions = NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch;

 

    NSLog(@"sousuo:%@,%@,%@",searchText,scope,storeResults);

 

    for (int i = 0; i < storeResults.count; i++)

 

    {

 

        NSString *storeString = [[storeResults objectAtIndex:i]objectForKey:@"name"];

 

        

 

        NSRange storeRange = NSMakeRange(0, storeString.length);

 

        

 

        NSRange foundRange = [storeString rangeOfString:searchText options:searchOptions range:storeRange];

 

       

 

        

 

        if (foundRange.length)

 

        {

 

             NSLog(@"foundRange:%d,%d",foundRange.length,foundRange.location);

 

            [tempResults addObject:storeString];

 

            [tempResultsId addObject:[[storeResults objectAtIndex:i]objectForKey:@"id"]];

 

        }

 

        

 

        

 

        NSLog(@"wodejieguo:%@,%@",[[storeResults objectAtIndex:i]objectForKey:@"id"],storeString);

 

    }

 

    //清空搜索內容Id

 

    [self.searchResultId removeAllObjects];

 

    [self.searchResult removeAllObjects];

 

    [self.searchResultId addObjectsFromArray:tempResultsId];

 

    [self.searchResult addObjectsFromArray:tempResults];

 

    NSLog(@"searchResult:%@,%@",searchResult,searchResultId);

 

    

 

}

說道這里關于搜索條的使用已經(jīng)基本完成,當然搜索列表選中跳頁可以借助自定義委托來實現(xiàn),這里就不多少了!

網(wǎng)站題目:iOS搜索條使用詳解
轉載來于:http://chinadenli.net/article16/joisgg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供面包屑導航品牌網(wǎng)站設計、虛擬主機企業(yè)建站、網(wǎng)站設計網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)
色婷婷视频免费在线观看| 国产农村妇女成人精品| 成年男女午夜久久久精品| 中文人妻精品一区二区三区四区| 黄片免费播放一区二区| 国产精品香蕉在线的人| 日韩欧美亚洲综合在线| 国产精品一区二区不卡中文 | 午夜国产福利在线播放| 日本男人女人干逼视频| 成人精品网一区二区三区| 精品香蕉国产一区二区三区| 粉嫩国产美女国产av| 色涩一区二区三区四区| 亚洲av日韩av高潮无打码| 久久本道综合色狠狠五月| 国产性色精品福利在线观看| 精品国产成人av一区二区三区| 国产一级精品色特级色国产| 国产精品人妻熟女毛片av久久| 亚洲男人的天堂就去爱| 欧美视频在线观看一区| 日本午夜精品视频在线观看| 久久精品少妇内射毛片| 日韩精品人妻少妇一区二区| 久久精品亚洲情色欧美| 国产又色又爽又黄又大| 一区中文字幕人妻少妇| 欧美日韩综合在线第一页| 国产精品内射视频免费| 在线免费观看一二区视频| 国产又大又猛又粗又长又爽| 国产成人国产精品国产三级| 99久久精品国产日本| 亚洲欧美日韩在线中文字幕| 中文字幕在线区中文色| 国产偷拍精品在线视频| 中文字幕日韩一区二区不卡| 国产麻豆一线二线三线| 高潮日韩福利在线观看| 亚洲视频偷拍福利来袭|