ui总结
来源:互联网 发布:淘宝上买什么 编辑:程序博客网 时间:2024/06/07 11:38
UI总结
selectImage、tintColor的设置
通过KeyPath Type Value 设置
静态表只能用在UITableViewController里面(直接拖NavigationCotroller即可)
声明初始化方法
-(instancetype)initWithDictionary:(NSDictionary *)dict;+(instancetype)tgMdoelWithDictionary:(NSDictionary *)dict;
方法的实现
-(instancetype)initWithDictionary:(NSDictionary *)dict{ if(self = [super init]) { [self setValuesForKeysWithDictionary:dict]; } return self;}+(instancetype)tgMdoelWithDictionary:(NSDictionary *)dict{ return [[self alloc]initWithDictionary:dict];}
数据源初始化(懒加载)
-(NSArray *)tgModel{ if (_tgModel == nil) { NSString *path = [[NSBundle mainBundle] pathForResource:@"tgs" ofType:@"plist"]; NSArray *array = [NSArray arrayWithContentsOfFile:path]; NSMutableArray *models = [NSMutableArray array]; for (NSDictionary *dict in array) { TGModel *model = [TGModel tgMdoelWithDictionary:dict]; //把model加到可变数组models中 [models addObject:model]; } // _tgModel = models; } // return _tgModel;}
重写set方法
-(void)setTgModel:(TGModel *)tgModel{ _tgModel = tgModel; _imgView.image = [UIImage imageNamed:tgModel.icon]; _titile.text = tgModel.title; _price.text = tgModel.price; _buycount.text = tgModel.buycount; }
UITableViewDataSource
注册单元格(加在ViewDidLoad中)
1、Nib注册 [_tableView registerNib:[UINib nibWithNibName:@"TGTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:identifier];2、注册单元格的类
组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}
行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.tgModels.count;}
单元格
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //xib(可复用单元格) //自定义的单元格 TGTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; //对cell的属性设置 TGModel *model = self.tgModels[indexPath.row]; cell.tgModel = model; return cell;}
添加tableView的头视图
-(void)addHeaderViewForTableView{ //表格的头视图设置的时候,对头视图设置frame //设置section的头视图的时候,需要设置头视图的高 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 100)]; scrollView.contentSize = CGSizeMake(ScreenW * 3, 100); scrollView.pagingEnabled = YES; for (int i = 0; i < 3; i++) { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenW * i , 0, ScreenW, 100)]; NSString *imageName = [NSString stringWithFormat:@"new_feature_%d",i + 1]; imageView.image = [UIImage imageNamed:imageName]; //把imageView添加到scrollView上 [scrollView addSubview:imageView]; } //把scrollView添加到头视图上 _tableView.tableHeaderView = scrollView;}
压栈(代理里的)
[self.navigationController pushViewController:detailVC animated:YES];
加载网页
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame][self.view addSubview:webView]; webView.delegate = self;//创建URLNSURL *url = [NSURL URLWithString:self.urlString];//根据创建的URL创建一个请求NSURLRequest *request = [NSURLRequest requestWithURL:url];//加载请求[webView loadRequest:request];
UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView;- (void)webViewDidFinishLoad:(UIWebView *)webView;- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
风火轮
[UIApplication sharedApplication].networkActivityIndicatorVisible = Bool;
设置UIBarButtonItem(以左Item为例)
-(void)setLeftBarBtnItem{ UIBarButtonItem *leftBarBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(edit:)]; // self.navigationItem.leftBarButtonItem = leftBarBtnItem;}
编辑
删除
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleDelete;}-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { //先删数据源(必须将数据源tgModel给改为可变数组) [self.tgModels removeObjectAtIndex:indexPath.row]; //移除界面(删除单元格的indexPath) [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; }}
移动
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{ //源的indexPath中取到要移动的行的数据 TGModel *model = self.tgModels[sourceIndexPath.row]; //从源的数据(tgModel)里将当前的数据(model)移除 [self.tgModels removeObjectAtIndex:sourceIndexPath.row]; //把当前数据插入到目标的indexPath位置 [self.tgModels insertObject:model atIndex:destinationIndexPath.row];}
搜索
-(void)addSearchController{ //创建搜索结果的视图控制器 TGResultTableViewController *tgResultVC = [[TGResultTableViewController alloc]initWithStyle:UITableViewStylePlain]; //赋值(搜索的数据上是tgModels里的数据) tgResultVC.array = self.tgModels; //初始化、把结果对象给searchController _searchController = [[UISearchController alloc] initWithSearchResultsController:tgResultVC]; //searchController的属性 //是否掩藏导航栏 _searchController.hidesNavigationBarDuringPresentation = YES; //朦版 _searchController.dimsBackgroundDuringPresentation = YES; //设置更新对象 _searchController.searchResultsUpdater = tgResultVC;}- (IBAction)search:(UIBarButtonItem *)sender { //把结果的视图控制器弹出 [self presentViewController:_searchController animated:YES completion:nil];}
数据过滤(UISearchResultsUpdating代理必须实现的方法)
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController{ NSString *filterString = searchController.searchBar.text; //数据过滤 if (filterString .length == 0) { _result = self.array; }else{ //过滤每一个数据模型 //过滤标题 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.title CONTAINS[CD] %@",filterString]; _result = [self.array filteredArrayUsingPredicate:predicate]; } //刷新表格 [self.tableView reloadData];}
0 0
- UI总结
- ui总结
- UI总结
- UI总结
- J2ME高级UI总结
- UI展现技术总结
- android--UI组件总结
- android--UI组件总结
- Android UI设计总结
- UI定制总结
- Android UI TabHost总结
- Android UI设计总结
- jquery-ui 使用总结
- android ui 开发总结
- UI -- UITextField总结
- Android UI设计总结
- Android UI设计总结
- extjs 项目UI总结
- [poj3114]Countries in War
- spark java.lang.OutOfMemoryError: Java heap space
- Android中Service的一个Demo例子
- 14、swift语言中协议的使用
- 【游】游戏Buff机制
- ui总结
- 9.UITouch 保存手指的信息(触摸的点
- 搭建maven+spring+freemaker+mybatis环境之一
- Dom4j中的中文编码问题
- 浮动
- 计数排序
- 【悟】终于入手PS4
- 基数排序
- python和php的面向对象