2013-06-05 2 views
0

아래의 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]; 

} 
+0

무엇이 문제입니까? 레이블 텍스트 설정에 대한 글꼴 설정에 동일한 유형의 조건부 표현식을 추가하기 만하면됩니다. 추악하지만 작동합니다. – allprog

+0

나는 위의 질문을 명확하게하기 위해 그것을 조정했다. – Steve

+0

만약'if genusSpecies : animal.commonName ...'은 무엇을 의미합니까? 이런 종류의 표현식에는':'연산자가 없다는 것이 확실합니다. 혹시라도 ==? – allprog

답변

0

문제는 조금 모호하지만 내 느낌은 당신이 장소에 거의 모든 것을 가지고있다 사용할 수 있습니다. 당신이 속 종 (species)을 보여주고 있는지를 결정하는데 사용할 수있는 BOOL을 생성하십시오. 이처럼 :

BOOL isGenuSpecies = (boolean expression to decide if this is a genus species) 

UIFont *textLabelFont = isGenusSpecies? StandardFont : ItalicFont; 
UIFont *detailTextLabelFont = isGenusSpecies? ItalicFont : StandardFont; 

[self.textLabel setFont: textLabelFont]; 

[self.detailTextLabel setFont: detailTextLabelFont]; 

이것은 당신이 StandardFontItalicFont 이전 somehere 정의 가지고 제공 작동합니다.

+0

고마워, 그랬어! – Steve

0

이탤릭체를 들어 당신은

[UIFont fontWithName:@"Helvetica-Oblique" size:13.0] 
+0

이것은 내가 묻고있는 질문에 대한 대답이 아닙니다. 조건을 묻는 중 글꼴 스타일이 이미 설정되었습니다. – Steve