//
// LJETableViewController.m
// LJESearchController
//
// Created by lije on 15/6/29.
// Copyright (c) 2015年 lije. All rights reserved.
//
#import "LJETableViewController.h"
#define kRowHeight 60
#define kSearchBarHeight 80
#define kSearchBarWidth self.view.frame.size.width
@interface LJETableViewController () {
UITableView *_tableview;
}
@property (nonatomic, strong) NSArray *dataSource;
@end
@implementation LJETableViewController
NSString * const CellIdentifier = @"CellIdentifier";
- (void)viewDidLoad {
[super viewDidLoad];
[self configureLayout];
}
- (void)configureLayout {
_tableview = [[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStylePlain];
[_tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
_tableview.delegate = self;
_tableview.dataSource = self;
[self.view addSubview:_tableview];
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kSearchBarWidth, kSearchBarHeight)];
[self.searchBar sizeToFit];
_tableview.tableHeaderView = self.searchBar;
_dataSource = @[@"wangyu", @"zhangjing", @"mali"];
self.dataSource = _dataSource;
}
#pragma mark - UITableviewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return kRowHeight;
}
#pragma mark - UITableviewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (indexPath.row < self.dataSource.count) {
cell.textLabel.text = self.dataSource[indexPath.row];
}
return cell;
}
@end
//
// LJESearchController.m
// LJESearchController
//
// Created by lije on 15/6/29.
// Copyright (c) 2015年 lije. All rights reserved.
//
#import "LJESearchController.h"
#import "LJETableViewController.h"
@interface LJESearchController ()<UISearchBarDelegate>
@property (nonatomic, strong) UISearchDisplayController *searchController;
@property (nonatomic, strong) LJETableViewController *tableSeaController;
@end
@implementation LJESearchController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Search";
self.tableSeaController = [[LJETableViewController alloc] init];
[self rn_addChildViewController:self.tableSeaController];
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.tableSeaController.searchBar contentsController:self];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tableSeaController.view.frame = self.view.bounds;
}
- (BOOL)shouldAutomaticallyForwardAppearanceMethods {
return YES;
}
- (void)rn_addChildViewController:(UIViewController *)controller {
[controller beginAppearanceTransition:YES animated:NO];
[controller willMoveToParentViewController:self];
[self addChildViewController:controller];
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:controller];
[controller endAppearanceTransition];
}
- (void)rn_removeChildViewController:(UIViewController *)controller {
if ([self.childViewControllers containsObject:controller]) {
[controller beginAppearanceTransition:NO animated:NO];
[controller willMoveToParentViewController:nil];
[controller.view removeFromSuperview];
[controller removeFromParentViewController];
[controller didMoveToParentViewController:nil];
[controller endAppearanceTransition];
}
}
@end
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u010606986/article/details/46692105