2013-08-01 3 views
0

몇 시간 동안 UIPickerView에 대한 예외를 쫓고 있습니다. 델리게이트 메서드 중 하나로 축소했습니다.하지만 정직하게는 알 수 없습니다. 아이폰에서 기본적으로 제공되는 폰트 패밀리 목록을 가져 와서 피커보기에서 자신이 나타내는 글꼴로 표시합니다.UIPickerView 예외

-(NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    NSLog(@"attributedTitleForRow"); 
    NSString *fontName = [self.fontFamilies objectAtIndex:row]; 
    NSLog(@"Font: %@", fontName); 
    NSDictionary *attributes = @{NSFontAttributeName:fontName}; 
    NSLog(@"Attributes: %@", attributes); 
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:fontName attributes:attributes]; 
    NSLog(@"Returning %@", attributedString); 
    return attributedString; 
} 

인쇄물 예외 :

2013-07-31 23:28:42.875 [4689:907] attributedTitleForRow 
2013-07-31 23:28:42.876 [4689:907] Font: Thonburi 
2013-07-31 23:28:42.879 [4689:907] Attributes: { 
    NSFont = Thonburi; 
} 
2013-07-31 23:28:42.881 [4689:907] Returning Thonburi{ 
    NSFont = Thonburi; 
} 
2013-07-31 23:28:42.884 [4689:907] attributedTitleForRow 
2013-07-31 23:28:42.886 [4689:907] Font: Snell Roundhand 
2013-07-31 23:28:42.887 [4689:907] Attributes: { 
    NSFont = "Snell Roundhand"; 
} 
2013-07-31 23:28:42.889 [4689:907] Returning Snell Roundhand{ 
    NSFont = "Snell Roundhand"; 
} 
2013-07-31 23:28:42.892 [4689:907] attributedTitleForRow 
2013-07-31 23:28:42.894 [4689:907] Font: Academy Engraved LET 
2013-07-31 23:28:42.896 [4689:907] Attributes: { 
    NSFont = "Academy Engraved LET"; 
} 
2013-07-31 23:28:42.898 [4689:907] Returning Academy Engraved LET{ 
    NSFont = "Academy Engraved LET"; 
} 
2013-07-31 23:28:42.920 [4689:907] -[__NSCFConstantString screenFontWithRenderingMode:]: unrecognized selector sent to instance 0x3977f364 
2013-07-31 23:28:42.922 [4689:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString screenFontWithRenderingMode:]: unrecognized selector sent to instance 0x3977f364' 

답변

1

NSFontAttributeName는 잘못된 이름이 있습니다. 예상 값은 글꼴 이름이 아니지만 UIFont 인스턴스입니다. 글꼴 이름을 기반으로 UIFont 개체를 만들려면 코드를 업데이트해야하고 attributes 사전에 UIFont을 사용하십시오.

NSFontAttributeName에 대한 문서를 읽어보십시오. UIFont 개체가 필요하며 NSString이 아니라는 것을 알려줍니다.