【发布时间】:2012-03-12 17:03:49
【问题描述】:
我的 viewController 中有几个 UIPickerViews。
这是其中之一需要自定义,因为它在 1 个选择器行中显示 2 个 UILabel。
我使用这些委托方法:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
// this method is use for normal pickers, and I would judge whether the picker that calling
// this method is a normal one or the special one by pickerView.
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view {
// and this one is specially for the special picker, I would also judge the pickerView is
//normal or special, if pickerView is normal, return nil, else I return a UIView with
//2 UIlabels.
}
但是现在经过我的调试,我发现如果两个方法一起实现,第二个总是被调用,而第一个似乎永远不会被调用,
这导致我的特殊选择器显示正确的数据,但其他人什么都没有。
我该怎么做?
如果我在第二种方法中给出所有选择器的数据,reusingView会不会成为问题,因为特殊选择器的reusingView与其他选择器的格式不同?
非常感谢!
【问题讨论】:
-
有趣...你在第二种方法中为其他选择器返回 nil 吗?
-
是的,这会是问题吗?如果我不返回任何内容,就会出现警告,所以...我会立即尝试删除该代码。
-
好吧..不。您不必删除该行,完全可以。
-
好吧.. 我认为只有两种选择。这两者都不是很简单 1. 使用不同的委托或 2. 创建一个看起来像 UIPicker 使用的 UILabel 并将其发送给其余的选择器,并使用现有的 titleForRow 方法来填写文本值
-
谢谢!我想使用不同的代表很适合我,但我该怎么办?我的意思是,它们都是 UIPickerView 并且在同一个 viewController 中,我如何区分这两个委托? @govi
标签: ios methods delegates uipickerview