---------------custom Tablefootviewdelegate class to manage the corresponding xib file----------------#import <uikit/uikit.h>// This protocol is used to standardize the way in which more data is loaded (more methods need to be loaded in the controller) @protocol MLTableFooterViewDelegate <NSObject> @optional-( void) Loadingmoredata; @end @interface mltablefooterview : uiview@property (nonatomic , Weak) id<mltablefooterviewdelegate> delegate;//is used to quickly create a Footview object. + (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{ //Initializes a nib object that contains all the information in the xib----- Another way to load a xib file //uinib *nib = [uinib nibwithnibname:@ "Mltablefooterview" bundle:nil]; //returns an array of all the files in the xib because there is only one in this xib, so Fistobject gets the custom view. //uiview *footview = [[nib instantiatewithowner:nil options:nil] firstobject]; return [[[nsbundle mainbundle] loadnibnamed:@ "Mltablefooterview" owner:nil options:nil] firstobject];} -(ibaction) loadbtnclick{ //Hide Load button self.loadbtn.hidden = yes; //Displays the view self.loadingview.hidden = no; being loaded //Show more data //use C language to implement delay (simulate load more) dispatch_after (Dispatch_time (dispatch_time_now, (int64_t) (1.0 * NSEC_PER_SEC) ), dispatch_get_main_queue (), ^{ if ([Self.delegate respondstoselector: @selector ( Loadingmoredata)]) { //load data [self.delegate loadingMoreData]; //Display Load button self.loadBtn.hidden = NO; //hidden "Loading" self.loadingView.hidden = YES; } });} @end part of the code------------in the////------controller (requires protocol mltablefooterviewdelegate) // Using a custom tablefooterview mltablefooterview *footer = [mltablefooterview footerview]; footer.delegate = self; //Sets the TableView proxy object to the current class object . self.tableview.tablefooterview = footer; //implements the Loadingmoredata method of the protocol, loading more data-( void) loadingmoredata{ //add more model data (virtual data) mltg *tg = [[mltg alloc]init];//where MLTG is a model class for my life, _TGS is the object of the controller, which is used to store all the data models . tg.icon = @ "ad_00"; tg.title = @ "new added buy data:"; " tg.price = @"; tg.buycount = @ "0"; //will data _tgs [_tgs addObject:tg]; in Heaven //Refresh the table (tells TableView to reload the model data, call TableView Reloaddata) [ Self.tableview reloaddata];}
iOS Custom Tablefooterview