IOS新手 有2个问题想请教各位大神
第一个问题是:
我现在有一段随机数据是这样的: Shiny Spork (3P9B1): Worth $10, recorded on 2015-05-16 14:44:21需要显示2段Sections,一段是worth 50以下的数据,一段是50以上的数据 这需要怎么实现。还有一个问题是如果让表格末端永远显示一个标题为NO more items!的cell对象。谢谢各位大神,实在不知道该怎么完成以上2个问题!!!!
第一个问题是:
我现在有一段随机数据是这样的: Shiny Spork (3P9B1): Worth $10, recorded on 2015-05-16 14:44:21需要显示2段Sections,一段是worth 50以下的数据,一段是50以上的数据 这需要怎么实现。还有一个问题是如果让表格末端永远显示一个标题为NO more items!的cell对象。谢谢各位大神,实在不知道该怎么完成以上2个问题!!!!
再建一个NSMutableArray和一个NSArray(这个数组固定50个)
代理返回3个Sections
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 0?50:1?[NSMutableArray count]:2?1;
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell;
if([indexPath section] == 0){
//通过代码自定义cell
cell = [self customCellWithOutXib:tableView withIndexPath:indexPath];
}else if(indexPath section] == 1){
cell = [self customCellWithOutXib:tableView withIndexPath:indexPath];
}
else{
//通过nib自定义cell
cell = [self customCellByXib:tableView withIndexPath:indexPath];
}
assert(cell != nil);
return cell;
}
根据你的需要组装数据源,控制tableview显示section的个数在tableview 的代理方法
-(NSInteger)numberOfSectionsInTableView 中来返回。
第二个问题:
可以在返回行的数据源的时候多加1,然后在cellForRowAtIndexPath 中来判断
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
return yourDataSource + 1;
}-(UITableViewCell *)tableivew:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//////说明是最后一条要渲染的cell, 这个cell就是你要显示的NO more items的cell
if (yourDataSource.count == indexPath.row) {
//////创建尾部的显示NO more items的cell
}else {
////////正常创建其实的cell
}
}