【发布时间】:2013-03-20 06:19:31
【问题描述】:
我在下面有这样的表格视图
姓名、出生率和天数(如 300、264)正在从不同的可变数组中显示
我使用了以下代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UIView *selectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 7, 320, 50)];
[selectionView setBackgroundColor: [UIColor clearColor]];
UILabel *callTypeLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, 150, 21)];
callTypeLabel.text = (NSString *)[_combinedNameArray objectAtIndex:[indexPath row]];
callTypeLabel.backgroundColor = [UIColor clearColor];
callTypeLabel.font = [UIFont boldSystemFontOfSize:15.0];
[selectionView addSubview:callTypeLabel];
UILabel *daystogo = [[UILabel alloc]initWithFrame:CGRectMake(200 , -2, 125, 30)];
daystogo.text = @"days to go";
daystogo.backgroundColor = [UIColor clearColor];
daystogo.font = [UIFont boldSystemFontOfSize:14.0];
[selectionView addSubview:daystogo];
UILabel *days = [[UILabel alloc]initWithFrame:CGRectMake(174 , -2, 125, 30)];
days.text = [NSString stringWithFormat:@"%@",[_daysremaining objectAtIndex:[indexPath row]]];
days.backgroundColor = [UIColor clearColor];
days.font = [UIFont boldSystemFontOfSize:14.0];
[selectionView addSubview:days];
UILabel *birthdate = [[UILabel alloc]initWithFrame:CGRectMake(5 , 22, 150, 21)];
birthdate.text = [NSString stringWithFormat:@"%@",[_combinedBirthdates objectAtIndex: [indexPath row]]];
birthdate.backgroundColor = [UIColor clearColor];
birthdate.font = [UIFont boldSystemFontOfSize:14.0];
[selectionView addSubview:birthdate];
[[cell viewWithTag:0] addSubview:selectionView];
return cell;
}
现在我的问题是我如何重新排序这些单元格,比如最短的天数应该是第一个,然后第二个比它大,依此类推 例子应该是这样的 25, 201, 256, 等等 姓名和出生率在数据库中,我将它们保存在数组中并对其进行处理以在另一个数组中查找剩余天数
请为此提出一些建议
【问题讨论】:
-
看看我的回答@user2189388
-
1) 您需要根据剩余天数对数组进行排序 2) 创建自定义类,并在计算剩余天数时创建自定义类的对象并将这些值分配给该对象并保存那在一个数组上。使用谓词对该数组进行排序并使用它而不是使用这三个数组