IOS自訂TableFooterView

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.