2017-08-25 87 views
0

根據文檔,選擇器視圖傾向於使用attributedTitleForRow而不是titleForRow。如果首選回報爲零,則選取器視圖將回退到titleForRow爲什麼不通過UIPickerView調用TitleForRow?

我正在實施這兩種方法,並且attributedTitleForRow永遠不會被調用。即使titleForRow返回零,而attributedTitleForRow返回NSAttributedString,它也不會被調用。但是,titleForRow總是被調用。

這是我有:

- (NSString *)pickerView:(UIPickerView *)pickerView 
      titleForRow:(NSInteger)row 
      forComponent:(NSInteger)component { 
    return @"Hello"; 
} 

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView 
      attributedTitleForRow:(NSInteger)row 
         forComponent:(NSInteger)component { 
    return [[NSAttributedString alloc] initWithString:@"World"]; 
} 
+1

如果只實現pickerView(_:attributedTitleForRow:forComponent :),那麼它是否被調用? – 3stud1ant3

+1

檢查此https://stackoverflow.com/questions/18945119/uipickerview-nsattributedstring-not-available-in-ios-7 –

+0

@ user1000不,仍然沒有調用,但viewForRow是 - 看起來像我將不得不那樣。 – ArielSD

回答

0

我沒有看到viewForRow委託方法也被稱爲。如果調用此方法,將不會運行titleForRowattributedTitleForRow

相關問題