為練手寫了乙個小的上拉載入更多下拉重新整理的小的dome 。
先來梳理一下:
上拉家在更多就是上拉之後在底部現實乙個檢視,用來提示使用者上拉載入更多,如果使用者上拉就出發事件,進行載入並在試圖中給予提示,同時後台載入資料,將新增的資料加入資料陣列,最後重新匯入列表;
下拉重新整理同樣的操作,只不過就是將陣列清空重新來匯入資料;
首先我們要建立兩個view 乙個是頂部顯示,乙個在底部顯示 ;
typedef enum insertstate;
@inte***ce headview : uiview
@property (nonatomic,strong) uiimageview *imageview;
@property (nonatomic,strong) uilabel *label;
@property (nonatomic,assign) insertstate insertstate;
@property (nonatomic,strong) uiactivityindicatorview *activity;
- (void)setinsertnomal;
- (void)setinsertdrapdown;
- (void)setinsertrun;
@end
@inte***ce footview : uiview
@property (nonatomic,strong) uiimageview *imageview;
@property (nonatomic,strong) uilabel *label;
@property (nonatomic,assign) insertstate insertstate;
@property (nonatomic,strong) uiactivityindicatorview *activity;
- (void)setinsertnomal;
- (void)setinsertdrapdoup;
- (void)setinsertrun;
@end
列舉用來指示檢視的當前狀態;
其實兩個檢視的內容什麼的都完全一樣;
//
// insertview.m
// refreshdome
//// created by 小屁孩 on 14-10-16.
//#import "insertview.h"
@implementation headview
@synthesize imageview;
@synthesize label;
@synthesize insertstate;
@synthesize activity;
- (id)initwithframe:(cgrect)frame
return self;
}//初始狀態
-(void)setinsertnomal
//下拉狀態
- (void)setinsertdrapdown
//重新整理狀態
- (void)setinsertrun
@end
@implementation footview
@synthesize imageview;
@synthesize label;
@synthesize insertstate;
@synthesize activity;
- (id)initwithframe:(cgrect)frame
return self;
}//初始狀態
- (void)setinsertnomal
//上拉狀態
- (void)setinsertdrapdoup
//載入狀態
- (void)setinsertrun
@end
最後就是列表了;
其實在這裡面需要注意的:
#import #import "insertview.h"
@inte***ce viewcontroller : uiviewcontroller@property (weak, nonatomic) iboutlet uitableview *table;
@property (nonatomic,strong) nsmutablearray *tablearray;
@end
#import "viewcontroller.h"
@inte***ce viewcontroller ()
@end
@implementation viewcontroller
@synthesize tablearray;
@synthesize table;
- (void)viewdidload
float hight =tablearray.count * 60 ;
if (tablearray.count * 60 < [[uiscreen mainscreen]bounds].size.height )
footview.frame = cgrectmake(0, hight, 320, 251);
[self addobserver:self forkeypath:@"tablearray" options:nskeyvalueobservingoptionnew context:nil];
}- (void) addtablemutablearray
self.tablearray = tablearray;
[footview setinsertnomal];
[self performselectoronmainthread:@selector(endthread) withobject:nil waituntildone:no];
}- (void)endthread
- (void) refesh
self.tablearray = array;
[headview setinsertnomal];
[self performselectoronmainthread:@selector(endthread) withobject:nil waituntildone:no];
}#pragma mark kvo
-(void)observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)context
footview.frame = cgrectmake(0, hight, 320, 251);
}#pragma mark tabledelegate
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath
cell.imageview.image = [tablearray objectatindex:indexpath.row];
cell.textlabel.text = @"nibbi";
return cell;
}#pragma mark - scrolldelegae
- (void)scrollviewdidenddragging:(uiscrollview *)scrollview willdecelerate:(bool)decelerate
if (footview.insertstate == insertstatedrapup)
}-(void)scrollviewdidscroll:(uiscrollview *)scrollview
//下拉重新整理轉換
if (scrollview.contentoffset.y < -60 && headview.insertstate == insertstatenomal)
}@end
ios 上拉載入下拉重新整理Dome
為練手寫了乙個小的上拉載入很多其它下拉重新整理的小的dome 先來梳理一下 上拉家在很多其它就是上拉之後在底部現實乙個檢視,用來提示使用者上拉載入很多其它,假設使用者上拉就出發事件。進行載入並在試圖中給予提示,同一時候後台載入資料,將加入的資料加入資料陣列,最後又一次匯入列表 下拉重新整理相同的操作...
下拉重新整理上拉載入
implements ixlistviewlistener 在oncreat裡面寫的 下拉重新整理是否啟用 xlistview.setpullrefreshenable true 載入更多是否啟用 xlistview.setpullloadenable true xlistview重新整理和載入更多...
下拉重新整理上拉載入
下拉載入上拉重新整理 需求 看看包是否有錯 然後在布局中把listview 改為 xlistview檔名 在activity找到控制項 xlistview xlistview view.findviewbyid r.id.xlistview xlistview setpullloadenable t...