下面的UITableView单元格根据搜索类型交替文本位置。文本标签设置为标准,详细信息文本当前设置为斜体。我希望这是相反的。基于查询格式的UITableView单元格文本字体
即如果genusSpecies:animal.commonName然后为textLabel = ItalicFont否则如果animal.commonName:genusSpecies然后为textLabel = StandardFont
我想这个规则应用到下面的代码。
- (void)setAnimal:(ITanimal *)animal forType:(ITSectionType)type {
_animal = animal;
BOOL isCommonType = (type == ITSectionTypeCommonName);
NSString *genusSpecies = animal.species];
[self.textLabel setFont:ItalicFont];
[self.textLabel setText:(!isCommonType)? genusSpecies : animal.commonName];
[self.detailTextLabel setFont:StandardFont];
[self.detailTextLabel setText:(!isCommonType)? animal.commonName : genusSpecies];
}
问题是什么?只需将相同类型的条件表达式添加到标签文本设置的字体设置中,即可完成。它很丑,但很有用。 – allprog
我已经调整了上面的问题,使其更清晰。 – Steve
'if genusSpecies:animal.commonName ...'是什么意思?我很确定这些表达式没有':'运算符。是不是有任何机会? – allprog