2

根据文档,选择器视图更喜欢使用attributedTitleForRowover 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"];
}
4

1 回答 1

1

我没有看到viewForRow委托方法也被调用了。如果调用此方法,则既不会运行,titleForRowattributedTitleForRow不会运行。

于 2017-08-30T22:46:53.083 回答