【问题标题】:Compare a sort list item with a string for a UItableview title将排序列表项与 UItableview 标题的字符串进行比较
【发布时间】:2012-06-24 18:02:49
【问题描述】:
我在表格视图中对列表进行了排序,但我不想将列表中的项目显示为行的标题。我需要将排序列表的第一项与字符串进行比较,如果相同,我想显示另一个字符串作为标题。
只是作为一个例子,更好地解释它:
if (first item of the sorted list == some string) {
cell.textlabel.text = @"name";
}
有可能做这样的事情吗?
【问题讨论】:
标签:
iphone
ios
uitableview
sorting
compare
【解决方案1】:
您的排序数组是否存储在NSArray 中?如果是这样,您可以使用:
if ([[sortedArray objectAtIndex:0] isEqualToString:@"Some String"]) {
cell.textlabel.text = @"name";
}
【解决方案2】:
如果我正确解释了这个问题,那么是的。如果第一项是一个单元格,大概就是这样,那么你可以这样做;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *firstCell = [yourTableView cellForRowAtIndePath:indexPath];
NSString *titleOfFirstCell = firstCell.textLabel.text;
然后您可以比较它以检查它应该更改为什么 - 我将把这个字符串称为“updatedTitle”。
titleOfFirstCell.textLabel.text = updatedTitle;
[firstCell setNeedsDisplay];
希望对你有帮助,
乔纳森