我們在有的時(shí)候需要用到scrollview橫向加載大小相同的多個(gè)控件。那么我們就需要重用啦,因?yàn)閯?chuàng)建太多會(huì)導(dǎo)致內(nèi)存劇增界面卡頓什么的一大堆問題,小弟想了半天整出了一個(gè)解決辦法寫了一個(gè)小小的demo并且封裝了一下,此代碼僅供各位參考。暴露的接口不是很多,如果各位有什么建議啊的寫得不好的地方請多多指教,如人不在直接反饋郵箱1474961002@qq.com給小弟一點(diǎn)建議,進(jìn)行改進(jìn)大家都不容易相互幫個(gè)忙嘛,在上代碼之前給進(jìn)來看的小伙伴微表謝意。好上代碼。

*/
#import"ViewController.h"
#import"UIListTableView.h"
#import"UIListViewCell.h"
@interfaceViewController(){
UIListTableView* _tableView;
}
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/**
這里我們需要注意的是我們列表的高度要根據(jù)方向來給。橫向的時(shí)候我們的高度我們肯定希望我們的控件和我們的列表的高度差不多所以這里橫向的時(shí)候我們列表的高度就是我們給cell的高度,也就是我們的
*/
_tableView= [[UIListTableViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,400)style:UITableViewStylePlain];
_tableView.delegate=self;
_tableView.dataSource=self;
//橫向豎向
_tableView.direction=UITableViewDirectionTypeHorizontal;
[self.viewaddSubview:_tableView];
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return5;
}
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
return300;
}
-(UITableViewCell* )tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
staticNSString* idStr =@"cell_list";
UIListViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:idStr];
if(cell ==nil) {
cell = [[UIListViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:idStrtableView:_tableView];
}
cell.showSeparate=YES;//是否需要分割線
cell.separateColor= [UIColorgreenColor];
returncell;
}
需要在cell里面創(chuàng)建自己想要的控件的話直接移步到我們的updateView里面去創(chuàng)建就好了。