我有一个自定义的UITableviewCell,其中包含一些UILabel。数据是从Web服务接收的,我想根据其中一个UILabel对它们进行排序。收到的数据存储在一个数组中。我怎样才能对它们进行排序?
谢谢! :) 编写代码以将数据添加到BO中的单元格:
cells.head.text = [[self.messageStore objectAtIndex:indexPath.section] subject];
cells.subhead.text = [[self.messageStore objectAtIndex:indexPath.section] messageli];
cells.signature.text=[AppConstants getUsername];
cells.viewCount.text = [NSString stringWithFormat:@"%@ Views",[[self.messageStore objectAtIndex:indexPath.section] viewsCount]];
cells.interested.text= [[self.messageStore objectAtIndex:indexPath.section] interestedCount];
cells.date.text = [[self.messageStore objectAtIndex:indexPath.section] creationDate];
[cells.image1 sd_setImageWithURL:[NSURL URLWithString:[[self.messageStore objectAtIndex:indexPath.section] imageURL]] placeholderImage:[UIImage imageNamed:@"no_photo.png"]];
cells.editZButton.hidden = NO;
cells.editZButton.tintColor = [UIColor whiteColor];
cells.deleteZButton.hidden = NO;
cells.amount.text = [NSString stringWithFormat:@"$ %@",[[self.messageStore objectAtIndex:indexPath.section] priceAmount]]; cells.editZButton.tag = indexPath.section;
cells.deleteZButton.tag = indexPath.section;
[cells.editZButton addTarget:self action:@selector(editButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cells.deleteZButton addTarget:self action:@selector(deleteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
答案 0 :(得分:1)
您可以使用谓词
对数据进行排序NSPredicate *predicate=[NSPredicate predicateWithFormat:@"Your_Key ==%@",Your_Value_For_Key];
NSArray *array=[Your_Array_Of_Data filteredArrayUsingPredicate:predicate];
答案 1 :(得分:1)
由于你没有给我们提供要排序的确切数组,我假设它只是一个简单的NSArray字符串。
您可以使用NSSortDescriptor对NSArray进行排序,如下所示
NSArray *arr = [[NSArray alloc] initWithObjects:@"Sam", @"John", @"Andrew", nil];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:NO];
NSArray *sortedArray = [arr sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
然后使用“sortedArray”重新加载tableview。
答案 2 :(得分:0)
下面是一般的方法,你可以试试。
RecycleViewAdapter