標籤:io ar os 使用 sp on 檔案 資料 bs
////---------------自訂TableFootViewDelegate類,用來管理對應的Xib檔案----------------#import <UIKit/UIKit.h>//該協議用來規範了載入更多資料的方法(需要用到控制器中的載入更多的方法)@protocol MLTableFooterViewDelegate <NSObject>@optional-(void)loadingMoreData;@end@interface MLTableFooterView : UIView@property(nonatomic , weak)id<MLTableFooterViewDelegate> delegate;//用來快速建立一個footView對象.+(instancetype)footerView;-(instancetype)initFooterView;@end#import "MLTableFooterView.h"@interface MLTableFooterView ()@property (weak, nonatomic) IBOutlet UIButton *loadBtn;@property (weak, nonatomic) IBOutlet UIView *loadingView;-(IBAction)loadBtnClick;@end@implementation MLTableFooterView+(instancetype)footerView{ return [[self alloc]initFooterView];}-(instancetype)initFooterView{ //初始化一個nib對象(包含xib中的所有資訊)-----另一種載入Xib檔案的方法 //UINib *nib = [UINib nibWithNibName:@"MLTableFooterView" bundle:nil]; //返回的是xib中所有的檔案的數組,因為此xib中只有一個,故用fistObject擷取改自訂的View. //UIView *footView = [[nib instantiateWithOwner:nil options:nil] firstObject]; return [[[NSBundle mainBundle] loadNibNamed:@"MLTableFooterView" owner:nil options:nil] firstObject];}-(IBAction)loadBtnClick{ //隱藏載入按鈕 self.loadBtn.hidden = YES; //顯示正在載入的view self.loadingView.hidden = NO; //顯示更多資料 //使用C語言實現延時(類比載入更多) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if ([self.delegate respondsToSelector:@selector(loadingMoreData)]) { //載入資料 [self.delegate loadingMoreData]; //顯示載入按鈕 self.loadBtn.hidden = NO; //隱藏"正在載入" self.loadingView.hidden = YES; } });}@end////------控制器中部分代碼------------(需要實現協議MLTableFooterViewDelegate) //使用自訂的tableFooterView MLTableFooterView *footer = [MLTableFooterView footerView]; footer.delegate = self; //將tableView的代理對象設定為當前類對象. self.tableView.tableFooterView = footer; //實現協議的loadingMoreData方法,載入更多資料-(void)loadingMoreData{ //添加更多的模型資料(虛擬資料) MLTg *tg = [[MLTg alloc]init];//其中MLTg是我生命的一個模型類,_tgs是控制器的對象,用來存放所有的資料模型. tg.icon = @"ad_00"; tg.title = @"新增加的團購資料.."; tg.price = @"100"; tg.buyCount = @"0"; //將資料天道_tgs中 [_tgs addObject:tg]; //重新整理表格(告訴tableView重新載入模型資料,調用tableView的reloadData) [self.tableView reloadData];}
IOS自訂TableFooterView