iOS UI 知识点
来源:互联网 发布:蛇蛇争霸网络不稳定 编辑:程序博客网 时间:2024/06/05 15:40
懒加载数据模型
- if语句判断是否为空
- 然后取路径
- 从路径中取出数组(数组内容为字典)
- 把字典转换成模型
返回模型
例子:- (NSMutableArray *)tgModels{if (_tgModels == nil) { NSString *path = [[NSBundle mainBundle] pathForResource:@"tgs" ofType:@"plist"]; NSArray *models = [NSArray arrayWithContentsOfFile:path]; _tgModels = [NSMutableArray array]; for (NSDictionary *dict in models) { QYTGModel *model = [QYTGModel tgModelWithDcitionary:dict]; [_tgModels addObject:model]; }}return _tgModels;}
自定义单元格
- contentView
- 创建xib中设置
- storyboard中设置
- layoutSubView(子视图化)
重写set方法的时候一定要先把set方法本身的任务写上
区分 section 和 tableView 的 头视图
- section 的头视图只需要设置行高
- tableView 的头视图要设置 frame
创建模型
- 模型属于一个类
- .h 文件中声明数模型中需要的属性和初始化方法(两个初始化方法—类初始化方法和对象初始化方法)
先写对象初始化初始化方法
-(instancetype)initWithDictionary:(NSDictionary *)dict{if (self = [super init]) { //第一种方法: _buycount = dict[@"buycount"]; _icon = dict[@"icon"]; _price = dict[@"price"]; _title = dict[@"title"]; // 第二种方法:灌入字典 //[self setValuesForKeysWithDictionary:dict];}return self;}
再写类初始化方法
+ (instancetype)tgModelWithDcitionary:(NSDictionary *)dict{ return [[self alloc] initWithDictionary:dict];}
设置导航栏的编辑按钮并实现编辑
移动的实现和编辑相似,先返回是否允许移动,然后移动方法:先从原处取出要移动的,删除原处内容,再把内容插入到目的处(移动的界面实现系统已经做好,我们只需要做数据源的处理)
在viewDidLoad中调用下两个方法:
//设置导航栏上右边的编辑-(void)setRightBarButtonItem{ UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(edit:)]; self.navigationItem.rightBarButtonItem = rightBarButtonItem;}//编辑 完成 切换- (void)edit:(UIBarButtonItem *)sender { if ([sender.title isEqualToString:@"编辑"]) { sender.title = @"完成"; [self.tableView setEditing:YES animated:YES]; } else { sender.title = @"编辑"; [self.tableView setEditing:NO animated:YES]; }}
实现代理方法:
//是否可以编辑- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES;}//编辑风格(插入和删除)- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row % 2) {//奇数行 return UITableViewCellEditingStyleInsert; }else{//偶数 return UITableViewCellEditingStyleDelete; }}//编辑的实现方法(注意必须把数据源删除)- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleInsert) { //更改数据源 [array insertObject:@"青云iOS" atIndex:indexPath.row + 1]; //更改界面 NSIndexPath *addIndexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:addIndexPath] withRowAnimation:UITableViewRowAnimationLeft]; }else if (editingStyle == UITableViewCellEditingStyleDelete){ //更改数据源 [array removeObjectAtIndex:indexPath.row]; //更改界面 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; }}
代码设置tabbar
-(void)awakeFromNib{ self.tabBarController.tabBar.tintColor = [UIColor brownColor]; UIImage *image = [[UIImage imageNamed:@"tabbar_contacts"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *selectedImage = [[UIImage imageNamed:@"tabbar_contactsHL"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通讯录" image:image selectedImage:selectedImage];}
下拉刷新
UIRefreshControl *refresh = [[UIRefreshControl alloc] init]; [self.tableView addSubview:refresh]; [refresh addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];-------------------------------- -(void)refresh:(UIRefreshControl *)refresh{ [refresh performSelector:@selector(endRefreshing) withObject:nil afterDelay:2];}
根据TextField输入的网址来访问对应的网页
注意要遵循UIWebViewDelegate,UITextFieldDelegate协议,并设置代理
NSURL *url = [NSURL URLWithString:_textField.text];NSURLRequest *request = [NSURLRequest requestWithURL:url];[_webView loadRequest:request];//设置状态栏的风火轮-(void)webViewDidStartLoad:(UIWebView *)webView{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];}-(void)webViewDidFinishLoad:(UIWebView *)webView{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];}
索引条
NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];_dict = [NSDictionary dictionaryWithContentsOfFile:path];NSArray *keys = _dict.allKeys;_keys = [keys sortedArrayUsingSelector:@selector(compare:)];//设置索引-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return _keys;}//点击索引-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ return index;}
搜索栏
必须遵循协议 UISearchResultsUpdating
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ if ([searchText isEqualToString:@""] || searchText == nil) {//clear _isSearching = NO; [_tableView reloadData]; return; } _isSearching = YES; //搜索关键字(谓词过滤,谓词是针对于数组的) NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[CD] %@",searchText]; NSMutableArray *resultArr = [NSMutableArray array]; for (NSString *key in _keys) { NSArray *array = _dict[key]; NSArray * resultArray = [array filteredArrayUsingPredicate:predicate]; [resultArr addObjectsFromArray:resultArray]; } _results = resultArr; [_tableView reloadData];}
1 0
- iOS UI 知识点
- IOS UI知识点收集
- ios中UI零散知识点记录
- iOS开发中的UI所有知识点
- UI知识点
- UI-知识点
- 初学ios必须了解的UI控件的知识点
- UI一点知识点
- UI知识点总结
- jQuery UI知识点总结
- UI-视频知识点总结
- UI -知识点回顾 一
- UI -知识点回顾 二
- UI -知识点回顾 三
- UI知识点总结
- iOS 知识点
- IOS知识点
- IOS知识点
- java的类学习
- gcc编译器
- 对二进制输出文件的认识
- leetcode-Remove Duplicates from Sorted List
- iOS回收键盘小见
- iOS UI 知识点
- Eclipse搭建scala环境(解决“JDT weaving is currently disabled”问题)
- QT写文件
- javascript(五)undefined false 字符串变量
- Linux于Windows使用Samba共享文件时文件属性nobody nogroup的解决办法
- 【线性代数公开课MIT Linear Algebra】 第十六课 Ax=b的解、最小二乘法与矩阵
- 利用中断调用实现简单的输入输出
- 素数距离问题(南阳acm)
- ListView实现简单分页