//
//  tableViewController.m
//  tableVC
//
//  Created by City--Online on 15/6/1.
//  Copyright (c) 2015年 CYW. All rights reserved.
//

#import "tableViewController.h"

@interface tableViewController ()<UISearchBarDelegate,UIScrollViewDelegate>
@property(nonatomic,strong) UISearchBar *searchBar;
@property(nonatomic,strong) NSArray *allData;
@property(nonatomic,strong) NSMutableArray *searchData;
@property(nonatomic,assign) NSInteger pageIndex;
@end

@implementation tableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _pageIndex=;
    //初始化数据
    _allData=@[@"abcd11",@"abcd12",@"abcd13",@"abcd14"];
    _searchData=[_allData copy];
    //初始化UISearchBar
    _searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width, )];
    //样式
    _searchBar.barStyle=UISearchBarStyleDefault;
    //代理
    _searchBar.delegate=self;
    //文本内容
    _searchBar.text=@"abcd";
    //提示文字
    _searchBar.prompt=";
//    //文本为空时显示内容
//    _searchBar.placeholder=@"qazwsx";
//    //bookmark按钮是否显示
//    _searchBar.showsBookmarkButton=YES;
//    //取消按钮是否显示
//    _searchBar.showsCancelButton=YES;
//    //搜索结果按钮显示
//    _searchBar.showsSearchResultsButton=YES;
//
    //bar的颜色(具有渐变效果)
    _searchBar.tintColor=[UIColor redColor];
    _searchBar.barTintColor=[UIColor whiteColor];
    _searchBar.searchBarStyle=UISearchBarStyleMinimal;
    //是否透明
    _searchBar.translucent=NO;
//   Scope的内容
    _searchBar.scopeButtonTitles=@[@"English",@"China"];
    //默认选择的Scope索引
    _searchBar.selectedScopeButtonIndex=;
    // 是否显示Scope
    _searchBar.showsScopeBar=YES;
    UIView *v=[[UIView alloc]initWithFrame:CGRectMake(, , self.view.bounds.size.width, )];
    v.backgroundColor=[UIColor yellowColor];
    //设置辅助输入视图
    _searchBar.inputAccessoryView=nil;
    // 键盘样式
    _searchBar.keyboardType=UIKeyboardTypeDefault;
    // 返回按钮样式
    _searchBar.returnKeyType=UIReturnKeyDone;
    self.tableView.tableHeaderView=_searchBar;
    self.tableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];

    //还有一些设置背景图片的一些属性方法 详见api
//    self.navigationItem.titleView=searchbar;

    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.modalPresentationCapturesStatusBarAppearance = NO;

}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    self.refreshControl=[[UIRefreshControl alloc]init];
    self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"啦啦啦啦儿童节"];
    [self.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//    [_searchBar resignFirstResponder];
    NSLog(@"%@", self.tableView.tableHeaderView.subviews);

}

-(void)refresh
{
    _pageIndex++;
    NSLog(");
    sleep();

    [self.refreshControl endRefreshing];
    [self.tableView reloadData];

}
//代理UISearchBarDelegate
//开始编辑
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    return YES;
}
// 将要结束编辑
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    NSLog(@"searchBarTextDidBeginEditing");
}
//是否可以结束编辑
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    return YES;
}
// 文本内容编辑结束
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
//    [searchBar resignFirstResponder];
    NSLog(@"searchBarTextDidEndEditing");
}
//文本内容改变
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    NSLog(@"textDidChange");
    NSLog(@"%@",searchText);
    ) {
        [searchBar resignFirstResponder];
        _searchData=[_allData copy];
        [self.tableView reloadData];
    }

}
//文本改变之前是否可以改变
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    return YES;
}
//查询按钮点击
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
    NSPredicate *predicate=[NSPredicate predicateWithFormat:@"SELF CONTAINS %@",searchBar.text];
    _searchData=[[_allData filteredArrayUsingPredicate:predicate] copy];
    [self.tableView reloadData];
}
//书签按钮点击
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
{
    NSLog(@"searchBarBookmarkButtonClicked");
}
//取消按钮点击
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];

}
// 搜索结果按钮点击
- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar
{
    NSLog(@"searchBarResultsListButtonClicked");

}
//Scope选择索引改变
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
    NSLog(@"%ld",selectedScope);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    // UIView默认的layoutMargins的值为 {8, 8, 8, 8}.在我们改变View的layoutMargins这个属性时,会触发- (void)layoutMarginsDidChange这个方法。我们在自己的View里面可以重写这个方法来捕获layoutMargins的变化。在大多数情况下,我们可以在这个方法里触发drawing和layout的Update。preservesSuperviewLayoutMargins这个属性默认是NO。如果把它设为YES,layoutMargins会根据屏幕中相关View的布局而改变。
#ifdef __IPHONE_8_0
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }

    if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
#endif
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return _pageIndex;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _searchData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier=@"identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

    }
     cell.textLabel.text=[NSString stringWithFormat:@"%@",[_searchData objectAtIndex:indexPath.row] ];

    return cell;
}

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.

    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
}

// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}

// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *v=[[UIView alloc]initWithFrame:CGRectMake(, , self.view.bounds.size.width, )];
    v.backgroundColor=[UIColor yellowColor];
    return v;

}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    ;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

UIKit 框架之UISearchBar、UITableViewController的更多相关文章

  1. UIKit框架使用总结--看看你掌握了多少

    一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...

  2. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  3. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  4. iOS-学习UIKIt框架的重要性

      前言: 众所周知,我们的移动设备的屏幕上可以展示很多图形界面,作为用户的我们可以通过屏幕上的图形界面浏览信息,也可以通过与图形界面的简单交互,在移动设备上实现各种各样的功能操作.....可以说,没 ...

  5. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

  6. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  7. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  8. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  9. 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架

    Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...

随机推荐

  1. html5 app开发

    如今html5技术越来越成熟,很多iPhone 及Android 上的移动APP都能用html5来开发完成.让我们一起来了解一下html5开发app. 一.HTML5框架开发的移动APP 编写开发游戏 ...

  2. Oracle数据库中 to_date()与24小时制表示法及mm分钟的显示

      一.在使用Oracle的to_date函数来做日期转换时,时候也许会直接的采用“yyyy-MM-dd HH:mm:ss”的格式作为格式进行转换,但是在Oracle中会引起错误:“ORA 01810 ...

  3. GitHub设置使用SSH Key,用TortoiseGit进行Clone仓库

    GitHub设置使用SSH Key的好处就是可以使用SSH连接,并且提交代码的时候可以不用输入密码,免密提交. 生成SSH Key 这里我们使用PuTTYgen来生成公钥(Public Key),私钥 ...

  4. 在ASP.NET MVC中使用区域来方便管理controller和view

    在ASP.NET MVC中使用区域来方便管理controller和view 在mvc架构中,一般在controllers和views中写所有控制器和视图, 太多控制器时候,为了方便管理,想要将关于pe ...

  5. C#通过rdp账密直接打开远程桌面

    思路是首先新建一个vbs脚本,再创建一个bat脚本,再创建rdp文件,运行顺序是vbs->bat->rdp.rdp文件里面包含远程电脑的账密和其它信息,这样就可以不用再输入账密,而在程序里 ...

  6. Flask 语音分析

    1. 安装api      百度组件 pip install baidu-aip 2.登录百度ai账号 ,建立一个账号 http://ai.baidu.com/ from aip import Aip ...

  7. Day 14 列表推导式、表达器、内置函数

    一. 列表推导式# l1 = []# for i in range(1,11):# l1.append(i)# print(l1)# #输出结果:[1, 2, 3, 4, 5, 6, 7, 8, 9, ...

  8. 廖雪峰Python学习笔记——类和实例

    Class MyList(list): __metaclass__ = ListMetaclass #它表示在创建MyList这个类时,必须通过 ListMetaclass这个元类的LIstMetac ...

  9. django url 路由设置技巧

    Django的url使用方法 利用Django开发站点.能够设计出很优美的url规则,假设url的匹配规则(包括正則表達式)组织得比較好,view的结构就会比較清晰.比較easy维护. 最简单的形式 ...

  10. FunDA(6)- Reactive Streams:Play with Iteratees、Enumerator and Enumeratees

    在上一节我们介绍了Iteratee.它的功能是消耗从一些数据源推送过来的数据元素,不同的数据消耗方式代表了不同功能的Iteratee.所谓的数据源就是我们这节要讨论的Enumerator.Enumer ...