`
zjjzmw1
  • 浏览: 1361609 次
  • 性别: Icon_minigender_1
  • 来自: 开封
社区版块
存档分类
最新评论

UISearchBar ios 搜索栏

    博客分类:
  • iOS
阅读更多

首先要在xib中拖动一个searchBar VC 也不用连方法的线。。。

 

UISearchBarDelegate,UISearchDisplayDelegate>

///搜索用的。

@property (strong, nonatomic) NSArray *arOriginal;

@property (strong, nonatomic) NSArray *arFiltered;

@property (readwrite, nonatomic) BOOL isSearching;

 

@property (weak, nonatomic) IBOutletUISearchBar *mySearchB;

 

 self.isSearching = NO;

    self.arOriginal = [NSArrayarrayWithObjects:@"Section0_Row1", @"Row1_Subrow1", @"Row1_Subrow2", @"Row1_Subrow3",nil];

 

    

 

    self.mySearchB.delegate = self;

 

 

 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

//    return [self.contents count];

    return (self.isSearching)?1:self.contents.count;

}

 

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

{

    return (self.isSearching)?self.arFiltered.count:[self.contents[section] count];

    

}

 

- (NSInteger)tableView:(SKSTableView *)tableView numberOfSubRowsAtIndexPath:(NSIndexPath *)indexPath

{

    if (self.isSearching) {

        return 0;

    }

    return [self.contents[indexPath.section][indexPath.row] count] - 1;

}

///这个都没有执行。。。

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

{

    if (self.isSearching) {///搜索到的结果。。。

        static NSString *CellIdentifier = @"UITableViewCell";

        

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        

        if (!cell)

            cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

        

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

        

        

        UIImageView *tempImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"DT_look.png"]];

        tempImageView.frame = CGRectMake(280, 18, 20, 16);

        [cell.contentView addSubview:tempImageView];

        

        return cell;

    }

    

    

    static NSString *CellIdentifier = @"SKSTableViewCell";

    

    SKSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    

    if (!cell)

        cell = [[SKSTableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

    

    cell.textLabel.text = self.contents[indexPath.section][indexPath.row][0];

    NSLog(@"cell.textLabel.text==--------=%@",cell.textLabel.text);

    ///现在没有section 并且都要有下拉的。。。。所以不用判断。

    cell.isExpandable = YES;

    

    return cell;

}

#pragma mark =====真正执行的方法========

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

{

    static NSString *CellIdentifier = @"UITableViewCell";

    

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    

    if (!cell)

        cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

    

    cell.textLabel.text = [NSString stringWithFormat:@"%@", self.contents[indexPath.section][indexPath.row][indexPath.subRow]];

    NSLog(@"cell.textLabel.text===%@",cell.textLabel.text);

    cell.detailTextLabel.text = cell.textLabel.text;

    

    UIImageView *tempImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"DT_look.png"]];

    tempImageView.frame = CGRectMake(280, 18, 20, 16);

    [cell.contentView addSubview:tempImageView];

    return cell;

}

 

 

 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    SKSTableViewCell *myCell = (SKSTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];

    NSLog(@"mycelll====%@",myCell.textLabel.text);

    self.isSearching = NO;

}

 

 

 

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

    if(self.searchDisplayController.searchBar.text.length>0) {

        self.isSearching=YES;

        NSString *strSearchText = self.searchDisplayController.searchBar.text;

        

        

//        NSMutableArray *ar=[NSMutableArray array];

        // correctly working ! Thanx for watching video !

        

        

//        for (NSString *d in self.arOriginal) {

//            if([d rangeOfString:strSearchText].length>0) {

//                [ar addObject:d];

//            }

//        }

//        self.arFiltered=[NSArray arrayWithArray:ar];

        

        ///下面是用谓词逻辑的方法。。///[c]忽略大小写.[d]忽略重音。这两个可以一起写。

        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS  [cd] %@", strSearchText];

        self.arFiltered = [self.arOriginal filteredArrayUsingPredicate:predicate];

        

        

    } else {

        self.isSearching=NO;

    }

    returnYES;

}

 

- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{

   ///每次搜索完的时候。

    self.isSearching = NO;

}

 

 

 

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

 

@end

1
0
分享到:
评论

相关推荐

    UISearchBar搜索栏示例程序

    - 可以通过子类化UISearchBar或者使用UIAppearance进行全局样式设置,实现自定义的搜索栏设计。 8. **响应式设计**: - 考虑到不同屏幕尺寸和设备,UISearchBar的布局和行为可能需要根据屏幕大小进行适配。 9. *...

    ios-uisearchbar 自定义搜索框.zip

    在iOS开发中,UISearchBar是苹果提供的一种用于实现搜索功能的UI组件,它通常被用在导航栏或者表视图的头部,以便用户能够快速输入关键词进行搜索。本项目"ios-uisearchbar 自定义搜索框.zip"是一个GitHub上的开源...

    iOS tableView点击更多 搜索栏

    总的来说,实现"iOS tableView点击更多 搜索栏"的功能涉及到UITableView的高级用法,包括自定义单元格行为、搜索过滤和用户交互处理。这要求开发者对iOS SDK有深入的理解,同时具备良好的编程实践。通过这个功能的...

    iOS UISearchBar 搜索功能的 demo

    首先,`UISearchBar` 是一个位于导航栏或者表视图顶部的UI控件,通常用作数据过滤和搜索。它包含一个文本字段和一个可选的清除按钮,用户可以在其中输入关键词进行搜索。`UISearchBar`与`UISearchController`一起...

    iOS App开发中UISearchBar搜索栏组件的基本用法整理

    在iOS应用开发中,UISearchBar是一个非常重要的组件,它用于实现搜索功能的用户界面。UISearchBar不仅提供了一个简洁的UI,还内置了许多便捷的功能。以下是对这个组件的基本用法进行的详细说明: **基本属性** 1. ...

    iOS定制UISearchBar导航栏同步iOS11的方法

    本文将重点介绍如何在iOS应用中定制`UISearchBar`,使其与iOS 11的导航栏风格保持同步。首先,我们需要理解iOS 11中`UISearchBar`的变化:它的高度增加到56像素,并且在未输入状态下的样式有所调整,如圆角、放大镜...

    ios搜索功能的实现源码

    这个“ios搜索功能的实现源码”提供了实例代码,可以帮助开发者理解并快速集成搜索功能到自己的应用中。我们将深入探讨如何在iOS应用中实现在表视图下的搜索功能。 首先,我们要明白iOS中的搜索功能主要通过...

    iOS之单独使用UISearchBar创建搜索框的示例

    在iOS应用开发中,UISearchBar是用于实现搜索功能的重要组件。本文将详细介绍如何单独使用UISearchBar创建一个搜索框,包括在导航栏上显示、设置其外观以及实现相关代理方法。 首先,我们需要在我们的...

    ios-UISearchBar.zip

    1. **文本输入**:用户可以在搜索栏中输入文本,`UISearchBar` 内置了一个`UITextField`,用于接收和显示用户输入。`UISearchBar` 提供了对用户输入的监听机制,开发者可以通过代理方法`searchBar:textDidChange:`来...

    ios7更改导航栏搜索框的取消按钮

    在iOS 7中,导航栏引入了搜索框(Search Bar),它允许用户在特定视图内进行快速搜索。本文将详细讲解如何在iOS 7中更改导航栏搜索框的取消按钮,并确保这种改变能够兼容iOS 6。 首先,我们需要了解在iOS中添加搜索...

    通过UItextField自定义UISearchBar

    但当我们想要自定义搜索栏的外观或行为时,可以直接操作`UITextField`对象。 要通过`UITextField`自定义`UISearchBar`,首先需要获取到`UISearchBar`中的`UITextField`实例。这可以通过以下代码实现: ```swift ...

    ios-搜索.zip

    这个控制器包含了搜索栏(UISearchBar)和搜索结果展示视图,允许用户在应用内部进行实时搜索,并能处理显示搜索结果的逻辑。 在"slideDemo"项目中,开发者可能会演示如何设置和配置UISearchController。这包括设置...

    UISearchBar使用Demo

    还可以添加搜索栏的搜索图标,或者自定义搜索框内的图片: ```objc UIImage *searchImage = [UIImage imageNamed:@"search_icon"]; [searchBar setImage:searchImage forSearchBarIcon:UISearchBarIconSearch state...

    IOS改变UISearchBar中搜索框的高度

    在iOS开发中,UISearchBar是用于用户输入搜索关键词的组件,通常出现在导航栏或表视图的顶部。在某些情况下,我们可能需要自定义UISearchBar的外观,特别是改变其搜索框的高度来适应界面设计。本文将详细介绍如何在...

    IOS 搜索及搜索bar

    在iOS中,搜索功能主要通过UISearchBar和UISearchController来实现,它们提供了丰富的定制性和易用性。 **UISearchBar**: UISearchBar是iOS SDK提供的一种UI组件,用于输入查询关键字。用户可以在其中输入文字,...

    ios-swift-demo15-搜索条(UISearchBar)的用法.zip

    `UISearchBar` 是苹果提供的UI控件,通常位于表视图(UITableView)的顶部或导航栏(UINavigationBar)内,用于提供用户输入搜索条件的界面。它包括一个文本字段(UITextField)和一个可选的取消按钮。用户可以输入...

    swift-UISearchBar的一个基本重新实现更容易的主题更换和更好的动画

    总的来说,"swift-UISearchBar的一个基本重新实现更容易的主题更换和更好的动画"项目旨在提供一个更灵活、可自定义的搜索栏组件,使开发者能够轻松地根据应用需求定制搜索栏的外观和交互体验,提升用户的使用感受。...

    UISearchBar扩展类,可以实现点击完成收回键盘

    在iOS开发中,`UISearchBar` 是一个常用的UI组件,用于搜索内容或过滤数据。它通常出现在导航栏、表视图的顶部等位置,提供用户输入查询条件的界面。然而,`UISearchBar` 默认的行为并不包含点击“完成”按钮后自动...

    iOS中的UISearchBar搜索框组件基础使用指南

    在iOS应用开发中,`UISearchBar` 是一个非常重要的组件,用于实现用户输入查询的关键字。它通常位于屏幕顶部或导航栏中,提供了一个简洁的界面来搜索数据。`UISearchBar` 包含了一些基本属性,如 `barStyle`、`text`...

Global site tag (gtag.js) - Google Analytics