tableview前端基础设计(初级版)
tableView前端基础设计
实现的最终效果

操作目的:熟悉纯代码编辑TableView和常用的相关控件SearchBar、NavigationBar、TabBar等,以及布局和基本功能的实现。
一、TabBar编辑
TabBar(标签栏)为实现多视图呈现的控制器,因为控制视图呈现,所以要在app完成之前进行设置。学习链接
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//创建window
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor=[UIColor clearColor];
//初始化一个tabBar
self.tb=[[UITabBarController alloc] init];
//设置为window的根控制器
self.window.rootViewController=self.tb;
self.tb.tabBar.backgroundColor=[UIColor whiteColor];
//设置状态栏的样式,控制不被navigationBar的颜色覆盖
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
//创建子控制器
[self MainLoadView];
[self.window makeKeyAndVisible];
return YES;
}
-(void)MainLoadView{
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
TestViewController *c1=[[TestViewController alloc] init];
UINavigationController *nb1=[[UINavigationController alloc]initWithRootViewController:c1];
//wx.tabBarItem.title=@"message";
//wx.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1];
c1.navigationItem.titleView=[self NavigationTitle:@"微信"];
contectViewController *c2=[[contectViewController alloc] init];
UINavigationController *nb2=[[UINavigationController alloc]initWithRootViewController:c2];
c2.navigationItem.titleView=[self NavigationTitle:@"通讯录"];
findViewController *c3=[[findViewController alloc] init];
UINavigationController *nb3=[[UINavigationController alloc]initWithRootViewController:c3];
c3.navigationItem.titleView=[self NavigationTitle:@"发现"];
meViewController *c4=[[meViewController alloc] init];
UINavigationController *nb4=[[UINavigationController alloc]initWithRootViewController:c4];
c4.navigationItem.titleView=[self NavigationTitle:@"我"];
self.tb.viewControllers=@[nb1,nb2,nb3,nb4];
[self customTabBar];
}
-(UILabel *)NavigationTitle:(NSString *)TitleText{
UILabel *title=[[UILabel alloc] initWithFrame:CGRectMake(, , , )];
title.backgroundColor=[UIColor clearColor];
title.textColor=[UIColor whiteColor];
title.font=[UIFont boldSystemFontOfSize:];
title.textAlignment=UITextAlignmentCenter;
title.text=TitleText;
return title;
}
//加载自定义的TabBarItem
-(void)customTabBar{
UITabBar *tabBar=self.tb.tabBar;
UITabBarItem *tabBarItem0 = [tabBar.items objectAtIndex:];
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:];
tabBarItem0.image = [[UIImage imageNamed:@"wechat-close.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem0.selectedImage = [[UIImage imageNamed:@"wechat-open.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem0.title=@"微信";
tabBarItem1.image = [[UIImage imageNamed:@"contact-close.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.selectedImage = [[UIImage imageNamed:@"contact-open.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.title=@"通讯录";
tabBarItem2.image = [[UIImage imageNamed:@"find-close.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem2.selectedImage = [[UIImage imageNamed:@"find-open.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem2.title=@"发现";
tabBarItem3.image = [[UIImage imageNamed:@"me-close.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem3.selectedImage = [[UIImage imageNamed:@"me-open.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem3.title=@"我";
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
kUIColorFromRGB(0x7a7e83), NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
kUIColorFromRGB(0x1aad19), NSForegroundColorAttributeName,
nil] forState:UIControlStateSelected];
}
二、搜索栏编辑
在ios8.0之前搜索栏是由SearchBar和SearchDisplayController联合控制呈现的,在ios8.0之后是由SearchController单独控制呈现。为了学习了解两种控制方式的区别,我在微信和通讯录页面用了两种不同的控制方式。最终体验就是改版后的省事多了,实现效果没有多大差别。(本测试中由于数据源格式不同所以呈现有些许差别)学习链接
改版前(关于SearchBar的部分代码,详情见demo)
@interface contectViewController ()<UISearchBarDelegate,UISearchDisplayDelegate>
@property (nonatomic,strong) UISearchBar *searchBar;
@property (nonatomic,strong) UISearchDisplayController *display;
@end @implementation contectViewController
- (void)viewDidLoad {
[self.searchBar setShowsScopeBar:NO];
[self search];
} -(void)search{
self.searchBar=[[UISearchBar alloc] init];
self.searchBar.placeholder=@"Search";
self.tableView.tableHeaderView = self.searchBar; self.display=[[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self]; self.searchBar.delegate=self;
self.display.searchResultsDataSource=self;
self.display.searchResultsDelegate=self;
self.display.delegate=self;
} //添加索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return self.titlearr; } -(NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
NSInteger count=;
for(NSString *character in self.titlearr){
if([[character uppercaseString] hasPrefix:title]){
return count;
}
count++;
}
return ;
} -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(nullable NSString *)searchString{ NSPredicate *resultPredicate=[NSPredicate predicateWithFormat:@"self contains[cd] %@",searchString];
self.searcharr=[self.contect filteredArrayUsingPredicate:resultPredicate];
return YES;
}
@end
改版后(SearchBarController的相关代码)
@interface TestViewController ()
@property (nonatomic,strong) SearchResultViewController *mySRTVC;
@property (nonatomic,strong) UISearchController *svc; @end @implementation TestViewController
-(NSArray *)dataSource{
if(!_dataSource){
_dataSource=[User demoData];
}
return _dataSource;
}
- (void)viewDidLoad {
self.mySRTVC=[[SearchResultViewController alloc] init];
self.mySRTVC.mainSearchController = self;
self.svc=[[UISearchController alloc] initWithSearchResultsController:self.mySRTVC];
[self.svc.searchBar sizeToFit];
self.tableView.tableHeaderView=self.svc.searchBar; //设置搜索控制器的结果更新代理对象
self.svc.searchResultsUpdater=self; /* //Scope:就是效果图中那个分类选择器
self.svc.searchBar.scopeButtonTitles=@[@"设备",@"软件",@"其他"];
//为了响应scope改变时候,对选中的scope进行处理 需要设置search代理
self.svc.searchBar.delegate=self;
*/
self.definesPresentationContext=YES;
} #pragma mark - UISearchResultsUpdating /**实现更新代理*/
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
//获取到用户输入的数据
NSString *searchText=searchController.searchBar.text;
NSMutableArray *searchResult=[[NSMutableArray alloc]init];
for (User *u in self.dataSource) {
NSRange range=[u.name rangeOfString:searchText];
if(range.length> ){
[searchResult addObject:u];
}
}
self.mySRTVC.searchResults=searchResult; /**通知结果ViewController进行更新*/
[self.mySRTVC.tableView reloadData];
} #pragma mark - UISearchBarDelegate
/**点击按钮后,进行搜索页更新*/
-(void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
[self updateSearchResultsForSearchController:self.svc];
}
本版本的demo:GitHub链接
用SourceTree上传Xcode的代码到GitHub请参考=>这里
tableview前端基础设计(初级版)的更多相关文章
- 基础DP(初级版)
本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...
- 前端基础之:JQuery(可编辑版)
前端基础之jquery 一 jQuery是什么? [1] jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. [2] ...
- NSIS安装制作基础教程[初级篇], 献给对NSIS有兴趣的初学者
NSIS安装制作基础教程[初级篇], 献给对NSIS有兴趣的初学者 作者: raindy 来源:http://bbs.hanzify.org/index.php?showtopic=30029 时间: ...
- 前端基础面试题(JS部分)
1.几种基本数据类型?复杂数据类型?值类型和引用数据类型?堆栈数据结构? 基本数据类型:Undefined.Null.Boolean.Number.String 值类型:数值.布尔值.null.und ...
- 前端基础面试题(js部分)
前端基础面试题(JS部分) 1.几种基本数据类型?复杂数据类型?值类型和引用数据类型?堆栈数据结构? 基本数据类型:Undefined.Null.Boolean.Number.String值类 ...
- web前端基础知识及快速入门指南
web前端基础知识及快速入门指南 做前端开发有几个月了,虽然说是几个月,但是中间断断续续的上课.考试以及其它杂七杂八的事情,到现在居然一直感觉自己虽然很多前端的知识很眼熟,却也感觉自己貌似也知识在门口 ...
- Python之路,Day4 - Python基础4 (new版)
Python之路,Day4 - Python基础4 (new版) 本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 ...
- 前后端分离之Web前端架构设计
架构设计:前后端分离之Web前端架构设计 在前面的文章里我谈到了前后端分离的一些看法,这个看法是从宏观的角度来思考的,没有具体的落地实现,今天我将延续上篇文章的主题,从纯前端的架构设计角度谈谈前后端分 ...
- html css 前端基础 学习方法及经验分享
前言: 入园第一天,想分享一点儿前端基础html css 的学习方法和一些经验给热爱前端,但是不知道从哪儿开始,依旧有些迷茫的新手朋友们.当然,适合每个人的学习方式不同,以下所讲的仅供参考. 一.关于 ...
随机推荐
- 中文乱码 URLEncode之后,后台获取仍是乱码问题详解
java中获取到参数的时候,这时候默认使用的是iso8859-1进行解码的,那么就再使用URLEncode的encoe方法对其进行编码一次,编码格式使用iso8859-1,这样我们就获得最初使用utf ...
- 常用正则表达式 c#
/// <summary> /// 是否手机号 /// </summary> /// <param name="str"></param& ...
- Quick Sort -- 快速排序算法
//参数说明: // int data[] : 待排序的数据数组 // int m : 下限值 // int n : 上限值 void QuickSort ( int data[] , int m , ...
- [NOIP2013D2]
T1 Problem 洛谷 Solution 这是线性扫描题吧. 就从1 ~ n 循环,若比起面高,则 ans += h[i] - h[i - 1]. Code #include<cmath&g ...
- Dubbo框架设计
各层说明 config配置层:对外配置接口,以 ServiceConfig, ReferenceConfig 为中心,可以直接初始化配置类,也可以通过 spring 解析配置生成配置类 proxy服务 ...
- 二叉树的简单操作(Binary Tree)
树形结构应该是贯穿整个数据结构的一个比较重要的一种结构,它的重要性不言而喻! 讲到树!一般都是讨论二叉树,而关于二叉树的定义以及概念这里不做陈诉,可自行搜索. 在C语言里面需要实现一个二叉树,我们需要 ...
- EFCore Owned Entity Types,彩蛋乎?鸡肋乎?之鸡肋篇
鸡肋 鸡肋(Chicken ribs),现代汉语词语,出自<三国志·魏书·武帝纪>裴松之注引<九州春秋>曰:"夫鸡肋,弃之如可惜,食之无所得,以比汉中,知王欲还也.& ...
- C语法简单测试
1.未初始化的枚举变量 /* uninitialized-enum.c */ #include <stdio.h> , black, blue}; int main(void) { enu ...
- browser_action' is only allowed for extensions but this is a legacy packaged app
manifest.json中不可包含调试代码: "app": { "launch": { "local_path": ...
- 学号 20175223 《Java程序设计》第 5 周学习总结
目录 教材学习内容总结 教材学习中的问题和解决过程 1. 在 jdb 调试时使用命令行参数. 代码调试中的问题和解决过程 1. 在jdb调试时通过命令行传入参数 2. "可能尚未初始化变量& ...