无法调用 titleForRow 方法 UIPickerView

发布于 2024-12-03 02:08:13 字数 255 浏览 2 评论 0原文

在我的 viewcontroller 类中,我有一个属性 UIViewPicker myPicker。在 didSelectRow 方法中(也由 UIPicker 委托实现。我尝试以下方法

NSString* temp = [self.myPicker titleForRow:1 inComponent:0].

,但它说找不到该方法,并说返回类型默认为“id”。

我做错了什么???`

in my viewcontroller class i have a property UIViewPicker myPicker. in didSelectRow method (also implemented by the UIPicker delegate. I try the following

NSString* temp = [self.myPicker titleForRow:1 inComponent:0].

However it says that the method is not found and says that return type defaults to "id".

What am i doing wrong????`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

顾铮苏瑾 2024-12-10 02:08:13

“它说找不到该方法”,因为这是 UIPickerViewDelegate 的委托方法。查看 Apple 文档。委托方法是实现的,而不是调用的!委托就像侦听器,它们的方法需要由实现委托的类来实现。这些方法是自动调用的,并且调用它们的顺序是预先定义的。您只需要知道调用它们的条件即可。

您始终可以创建自己的方法,只要它们与委托方法不同即可。

"it says that the method is not found" because this a delegate method for UIPickerViewDelegate. Check the Apple Documentation. Delegate methods are implemented, NOT called! Delegates are like listeners and their methods need to be implemented by the class that implements the delegates. The methods are called automatically and the order in which they are called is predefined. You only have to know the conditions under which they are called.

You can always create your own methods as long as they are different from the delegate methods.

野の 2024-12-10 02:08:13

这是一个委托方法,您可以使用它来设置行的特定标题。我不相信你可以通过这样的实例来调用它。您需要在当前控制器(应该实现 UIPickerViewDelegate)中单独实现此方法,然后从那里开始工作。

例如

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

if (row==1)
    return @"Title 1";

if (row==2)
    return @"Title 2";

return @"Default Title";

}

This is a delegate method which you can use to set particular titles for rows. I don't believe you can call it via an instance like this. You'll need to implement this method separately in your current controller (which should implement the UIPickerViewDelegate) and then work from there.

e.g.

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

if (row==1)
    return @"Title 1";

if (row==2)
    return @"Title 2";

return @"Default Title";

}

剑心龙吟 2024-12-10 02:08:13

尝试以下声明

NSString* temp = [self pickerView:self.myPicker titleForRow:1 forComponent:0];

,我认为它会解决您的问题。

谢谢萨蒂亚

try the following statement

NSString* temp = [self pickerView:self.myPicker titleForRow:1 forComponent:0];

I think,it will solve your problem.

Thanks

Satya

遗失的美好 2024-12-10 02:08:13

尝试这样的操作。

NSString* temp = [pickerView titleForRow:1 inComponent:0];

您可以在提到的方法中

You can try like this

NSString* temp = [pickerView titleForRow:1 inComponent:0];

inside the mentioned method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文