当前位置: 首页 > news >正文

垫江网站建设报价网站添加wordpress博客

垫江网站建设报价,网站添加wordpress博客,西安网店培训班,自建外贸推广网站有哪些iOS开发UI篇#xff0d;在UItableview中实现加载更多功能 一、实现效果 点击加载更多按钮#xff0c;出现一个加载图示#xff0c;三秒钟后添加两条新的数据。 二、实现代码和说明 当在页面#xff08;视图部分#xff09;点击加载更多按钮的时候#xff0c;主页面#…iOS开发UI篇在UItableview中实现加载更多功能 一、实现效果   点击加载更多按钮出现一个加载图示三秒钟后添加两条新的数据。   二、实现代码和说明 当在页面视图部分点击加载更多按钮的时候主页面主控制器会加载两条数据进来。 视图部分的按钮被点击的时候要让主控制器加载数据刷新表格2B青年会在视图中增加一个主控制器的属性通过这个属性去调用进行加载但在开发中通常通过代理模式来完成这个操作。 下面分别是两种实现的代码。 1、项目结构和说明 说明加载更多永远都放在这个tableview的最下端因此这里设置成了这个tableview的tableFooterView。  self.tableview.tableFooterViewfooterview; 在实现上通过xib来进行处理考虑到左右的留白以及点击后的要切换到加载按钮和文字要同时控制图标和文字因此把加载图标和文字提示放在了一个view中以便控制这个xib已经和YYfooterview.xib进行了关联通过这个类来控制xib。 2、实现代码 1.垃圾代码 数据模型部分 YYtg.h文件 // // YYtg.h // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import Foundation/Foundation.h #import Global.hinterface YYtgModel : NSObject property(nonatomic,copy)NSString *icon; property(nonatomic,copy)NSString *buyCount; property(nonatomic,copy)NSString *title; property(nonatomic,copy)NSString *price;//对外接口 YYinitH(tg) end YYtg.m文件 // // YYtg.m // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import YYtgModel.himplementation YYtgModel YYinitM(tg) end 注意对于数据转模型部分的构造方法接口和实现代码已经通过自定义带参数的宏来进行了封装。 封装代码如下 #ifndef _0____________Global_h #define _0____________Global_h/*** 自定义带参数的宏*/ #define YYinitH(name) -(instancetype)initWithDict:(NSDictionary *)dict;\ (instancetype)name##WithDict:(NSDictionary *)dict;#define YYinitM(name) -(instancetype)initWithDict:(NSDictionary *)dict\ {\if (self[super init]) {\[self setValuesForKeysWithDictionary:dict];\}\return self;\ }\ \ (instancetype)name##WithDict:(NSDictionary *)dict\ {\return [[self alloc]initWithDict:dict];\ }\#endif 视图部分 YYtgcell.h文件 // // YYtgcell.h // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import UIKit/UIKit.h #import YYtgModel.hinterface YYtgcell : UITableViewCell property(nonatomic,strong)YYtgModel *yytg;//把加载数据使用xib创建cell的内部细节进行封装 (instancetype)tgcellWithTableView:(UITableView *)tableView; end YYtgcell.m文件 // // YYtgcell.m // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import YYtgcell.h //私有扩展 interface YYtgcell() property (strong, nonatomic) IBOutlet UIImageView *img; property (strong, nonatomic) IBOutlet UILabel *titlelab; property (strong, nonatomic) IBOutlet UILabel *pricelab; property (strong, nonatomic) IBOutlet UILabel *buycountlab; end implementation YYtgcell#pragma mark 重写set方法完成数据的赋值操作 -(void)setYytg:(YYtgModel *)yytg {_yytgyytg;self.img.image[UIImage imageNamed:yytg.icon];self.titlelab.textyytg.title;self.pricelab.text[NSString stringWithFormat:$%,yytg.price];self.buycountlab.text[NSString stringWithFormat:已有%人购买,yytg.buyCount]; }(instancetype)tgcellWithTableView:(UITableView *)tableView {static NSString *identifier tg;YYtgcell *cell[tableView dequeueReusableCellWithIdentifier:identifier];if (cellnil) {//如何让创建的cell加个戳//对于加载的xib文件可以到xib视图的属性选择器中进行设置cell[[[NSBundle mainBundle]loadNibNamed:tgcell owner:nil options:nil]firstObject];NSLog(创建了一个cell);}return cell; }end YYfooterview.h文件 // // YYfooterview.h // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import UIKit/UIKit.h class YYViewController; interface YYfooterview : UIView property(nonatomic,strong) YYViewController *controller; end YYfooterview.m文件 // // YYfooterview.m // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import YYfooterview.h #import YYViewController.hinterface YYfooterview () property (strong, nonatomic) IBOutlet UIActivityIndicatorView *loadingview; property (strong, nonatomic) IBOutlet UIButton *loadbtn;end implementation YYfooterview - (IBAction)loadbtclick {NSLog(按钮被点击了);//隐藏按钮self.loadbtn.hiddenYES;//显示菊花self.loadingview.hiddenNO;#warning 模拟发送网络请求, 3秒之后隐藏菊花dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{// 3.调用控制的加载数据方法[self.controller LoadMore];// 4.隐藏菊花视图self.loadingview.hidden YES;// 5.显示按钮self.loadbtn.hidden NO;}); }end 主控制器 YYViewController.h文件 // // YYViewController.h // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import UIKit/UIKit.hinterface YYViewController : UIViewController //公开接口 //- (void)LoadMore; end YYViewController.m文件 // // YYViewController.m // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import YYViewController.h #import YYtgModel.h #import YYtgcell.h #import YYfooterview.hinterface YYViewController ()UITableViewDataSource,UITableViewDelegate property (strong, nonatomic) IBOutlet UITableView *tableview;property(strong,nonatomic)NSMutableArray *tg; endimplementation YYViewController#pragma mark-加载数据方法 -(void)LoadMore {//创建模型YYtgModel *tgmodel[[YYtgModel alloc]init];tgmodel.title菜好上桌;tgmodel.icon5ee372ff039073317a49af5442748071;tgmodel.buyCount20;tgmodel.price10000;//将模型添加到数组中[self.tg addObject:tgmodel];YYtgModel *tgmodelq[[YYtgModel alloc]init];tgmodelq.title菜好上桌1;tgmodelq.icon5ee372ff039073317a49af5442748071;tgmodelq.buyCount20;tgmodelq.price10000;[self.tg addObject:tgmodelq];//刷新表格[self.tableview reloadData]; }- (void)viewDidLoad {[super viewDidLoad];self.tableview.rowHeight80.f;//加载底部视图//从xib中获取数据UINib *nib[UINib nibWithNibName:YYfooterview bundle:nil];YYfooterview *footerview[[nib instantiateWithOwner:nil options:nil] firstObject];self.tableview.tableFooterViewfooterview;//设置控制footerview.controllerself; } #pragma mark- 懒加载 -(NSArray *)tg {if (_tgnil) {NSString *fullpath[[NSBundle mainBundle]pathForResource:tgs.plist ofType:nil];NSArray *temparray[NSArray arrayWithContentsOfFile:fullpath];NSMutableArray *arrayM[NSMutableArray arrayWithCapacity:temparray.count];for (NSDictionary *dict in temparray) {YYtgModel *tg[YYtgModel tgWithDict:dict];[arrayM addObject:tg];}_tgarrayM;}return _tg; }#pragma mark- xib创建cell数据处理#pragma mark 多少组 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 1; }#pragma mark多少行 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return self.tg.count; }#pragma mark设置每组每行 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {//1.创建cellYYtgcell *cell[YYtgcell tgcellWithTableView:tableView];//2.获取当前行的模型,设置cell的数据YYtgModel *tgself.tg[indexPath.row];cell.yytgtg;//3.返回cellreturn cell; }#pragma mark- 隐藏状态栏 -(BOOL)prefersStatusBarHidden {return YES; }end 2.通过代理完成 当按钮被点击的时候视图部分本身不干活而是通知它的代理控制器完成接下来的操作。 该部分代码在1的基础上对下面几个文件进行了修改 视图部分 YYfooterview.h文件 // // YYfooterview.h // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import UIKit/UIKit.h class YYViewController ,YYfooterview; //约定协议 protocol YYfooterviewDelegate NSObject -(void)footerviewLoadMore; endinterface YYfooterview : UIView//声明一个id类型属性遵守了协议的“人”即可成为它的代理 property(nonatomic,strong)idYYfooterviewDelegate delegate; //property(nonatomic,strong) YYViewController *controller; end YYfooterview.m文件 // // YYfooterview.m // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import YYfooterview.h #import YYViewController.hinterface YYfooterview () property (strong, nonatomic) IBOutlet UIActivityIndicatorView *loadingview; property (strong, nonatomic) IBOutlet UIButton *loadbtn;end implementation YYfooterview - (IBAction)loadbtclick {NSLog(按钮被点击了);//隐藏按钮self.loadbtn.hiddenYES;//显示菊花self.loadingview.hiddenNO;#warning 模拟发送网络请求, 3秒之后隐藏菊花dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{// 3.调用控制的加载数据方法 // [self.controller LoadMore];//通知代理需要进行判断代理有没有实现相应的方法[self.delegate footerviewLoadMore];// 4.隐藏菊花视图self.loadingview.hidden YES;// 5.显示按钮self.loadbtn.hidden NO;}); }end 主控制器部分 YYViewController.h文件 // // YYViewController.h // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import UIKit/UIKit.hinterface YYViewController : UIViewController //公开接口 //- (void)LoadMore; end YYViewController.m文件 // // YYViewController.m // 02-团购使用xib和类完成数据展示 // // Created by apple on 14-5-29. // Copyright (c) 2014年 itcase. All rights reserved. //#import YYViewController.h #import YYtgModel.h #import YYtgcell.h #import YYfooterview.hinterface YYViewController ()UITableViewDataSource,UITableViewDelegate,YYfooterviewDelegate property (strong, nonatomic) IBOutlet UITableView *tableview;property(strong,nonatomic)NSMutableArray *tg; endimplementation YYViewController#pragma mark-加载数据方法 -(void)footerviewLoadMore {//创建模型YYtgModel *tgmodel[[YYtgModel alloc]init];tgmodel.title菜好上桌;tgmodel.icon5ee372ff039073317a49af5442748071;tgmodel.buyCount20;tgmodel.price10000;//将模型添加到数组中[self.tg addObject:tgmodel];YYtgModel *tgmodelq[[YYtgModel alloc]init];tgmodelq.title菜好上桌1;tgmodelq.icon5ee372ff039073317a49af5442748071;tgmodelq.buyCount20;tgmodelq.price10000;[self.tg addObject:tgmodelq];//刷新表格[self.tableview reloadData]; } //-(void)LoadMore //{ // //创建模型 // YYtgModel *tgmodel[[YYtgModel alloc]init]; // tgmodel.title菜好上桌; // tgmodel.icon5ee372ff039073317a49af5442748071; // tgmodel.buyCount20; // tgmodel.price10000; // //将模型添加到数组中 // [self.tg addObject:tgmodel]; // // YYtgModel *tgmodelq[[YYtgModel alloc]init]; // tgmodelq.title菜好上桌1; // tgmodelq.icon5ee372ff039073317a49af5442748071; // tgmodelq.buyCount20; // tgmodelq.price10000; // // [self.tg addObject:tgmodelq]; // //刷新表格 // [self.tableview reloadData]; //}- (void)viewDidLoad {[super viewDidLoad];self.tableview.rowHeight80.f;//加载底部视图//从xib中获取数据UINib *nib[UINib nibWithNibName:YYfooterview bundle:nil];YYfooterview *footerview[[nib instantiateWithOwner:nil options:nil] firstObject];self.tableview.tableFooterViewfooterview;//设置控制 // footerview.controllerself;//设置代理footerview.delegateself; } #pragma mark- 懒加载 -(NSArray *)tg {if (_tgnil) {NSString *fullpath[[NSBundle mainBundle]pathForResource:tgs.plist ofType:nil];NSArray *temparray[NSArray arrayWithContentsOfFile:fullpath];NSMutableArray *arrayM[NSMutableArray arrayWithCapacity:temparray.count];for (NSDictionary *dict in temparray) {YYtgModel *tg[YYtgModel tgWithDict:dict];[arrayM addObject:tg];}_tgarrayM;}return _tg; }#pragma mark- xib创建cell数据处理#pragma mark 多少组 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 1; }#pragma mark多少行 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return self.tg.count; }#pragma mark设置每组每行 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {//1.创建cellYYtgcell *cell[YYtgcell tgcellWithTableView:tableView];//2.获取当前行的模型,设置cell的数据YYtgModel *tgself.tg[indexPath.row];cell.yytgtg;//3.返回cellreturn cell; }#pragma mark- 隐藏状态栏 -(BOOL)prefersStatusBarHidden {return YES; }end  转载于:https://www.cnblogs.com/yipingios/p/5549874.html
http://www.pierceye.com/news/296236/

相关文章:

  • 数据展示网站模板备案 非网站备案
  • 邯郸做网站推广找谁jsp做的网站代码
  • php网站开发怎么接私活全能医院网站管理系统
  • 观止网站建设10元建站
  • 什么网站做聚乙烯醇好的三亚旅游攻略
  • 建设网站目的直播间网站开发
  • 网站项目评价怎么在网站上做签到
  • 深圳网站建设制作哪家好长春网站开发培训
  • 模板下载网站网络公司网站开发
  • 广州市酒店网站设计重庆网站seo设计
  • p2p网站如何建设网站建设 源美设计
  • 电商网站建设图片ps网站首页设计图
  • 网站优化简历模板用土豆做美食的视频网站
  • 帮企业建设网站销售微信朋友圈广告在哪里做
  • 曲阜做网站的公司wordpress两个域名
  • 做设备租赁的网站如何把自己做的网站发布到网上
  • 做网站运营有前景吗关于网站建设意见和建议
  • 如何给网站的关键词做排名南海做网站公司
  • 仿站软件邢台手机网站建设价格
  • 学校网站开发与设计什么是网络营销促销?
  • 胶州网站搭建企业wordpress站内信群发
  • WordPress做的网站源代码网站备案失效
  • 承德网站制作与建设wordpress h5播放器
  • .net网站程序网站建设 报告
  • 中国做的电脑系统下载网站好互动网站
  • 网站使用培训方案网站后台工程师
  • 做网站优化找谁简单网站页面
  • 青岛做公司网站佛山网站建设锐艺传播
  • 江苏商城网站制作公司网站备案时间
  • 网站开发用到什么技术公司做影视网站侵权