我們在有的時候需要用到scrollview橫向加載大小相同的多個控件。那么我們就需要重用啦况毅,因為創(chuàng)建太多會導致內(nèi)存劇增界面卡頓什么的一大堆問題,小弟想了半天整出了一個解決辦法寫了一個小小的demo并且封裝了一下客情,此代碼僅供各位參考迅细。暴露的接口不是很多,如果各位有什么建議啊的寫得不好的地方請多多指教慕爬,如人不在直接反饋郵箱1474961002@qq.com給小弟一點建議窑眯,進行改進大家都不容易相互幫個忙嘛,在上代碼之前給進來看的小伙伴微表謝意医窿。好上代碼磅甩。
*/
#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ù)方向來給僧叉。橫向的時候我們的高度我們肯定希望我們的控件和我們的列表的高度差不多所以這里橫向的時候我們列表的高度就是我們給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)建就好了棺榔。