【发布时间】:2017-08-25 16:11:13
【问题描述】:
根据文档,选择器视图更喜欢使用 attributedTitleForRow 而不是 titleForRow。如果首选返回 nil,则选择器视图回退到 titleForRow。
我正在实现这两种方法,attributedTitleForRow 永远不会被调用。即使titleForRow 返回 nil,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"];
}
【问题讨论】:
-
如果只实现 pickerView(_:attributedTitleForRow:forComponent:) ,那么它会被调用吗?
-
@user1000 不,仍然没有调用,但 viewForRow 是 - 看起来我将不得不走那条路。
标签: ios objective-c xcode uipickerview uipickerviewdelegate