【问题标题】:Why doesn't attributedTitleForRow get called with a UIPickerView?为什么不使用 UIPickerView 调用属性TitleForRow?
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多