首页 > 移动平台 > 详细

iOS学习笔记12-UISearchBar

时间:2016-02-22 14:44:49      阅读:224      评论:0      收藏:0      [点我收藏+]

首先做一个假数据

    data=[NSArray arrayWithObjects:@"w",@"wwe",@"wwweer",@"Eee",@"fff",@"fffq", nil];

 

定义一个bool 值是isFind 初始值设为0

    isfind=NO;即不是搜索状态

 

 

 设置搜索状态和非搜索状态的不同的容行数

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

    if (isfind==NO) {

        return data.count;

    }

    else

    {

        return finddata.count;

    }

}

 

 

设置cell

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

    static NSString *cellid=@"cellid";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid];

    if (cell==nil) {

        cell=[[UITableViewCell alloc]initWithStyle: UITableViewCellStyleDefault reuseIdentifier:cellid];

    }

    if (isfind==YES) {

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

    }

    return cell;

}

 

iOS学习笔记12-UISearchBar

原文:http://www.cnblogs.com/adodo/p/5206893.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!