根据文档,选择器视图更喜欢使用attributedTitleForRow
over titleForRow
。如果首选返回 nil,则选择器视图回退到titleForRow
.
我正在实现这两种方法,并且attributedTitleForRow
永远不会被调用。即使titleForRow
返回 nil 并attributedTitleForRow
返回 an 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"];
}