'UIButton' 没有可见的@interface 声明了选择器 'setTitle:'

No visible @interface for 'UIButton' declares the selector 'setTitle:'

我正在开发一个测验应用程序,我从文本文件中加载问题。

我有一个适用于 OS X 的应用程序版本,但是现在我正在为 iOS 重新创建它,但我遇到了一些我不确定的问题。

这是将问题加载到应用界面的代码:

- (void)loadQuestionsAndAnswersIntoInterface {

    NSDictionary *QADictionary = [questionsAndAnswers objectAtIndex:currentQuestion];

    [question setStringValue:[QADictionary valueForKey:@"question"]];
    [answer1 setTitle:[[QADictionary valueForKey:@"answers"] objectAtIndex:0]];
    [answer2 setTitle:[[QADictionary valueForKey:@"answers"] objectAtIndex:1]];
    [answer3 setTitle:[[QADictionary valueForKey:@"answers"] objectAtIndex:2]];

    //[question setValue:[QADictionary valueForKey:@"question"]];
}

当答案是 NSButtons 而问题是 NSTextfield 时,此代码在 OS X 应用程序上运行良好。

但是现在,当 UIButtons 和 UITextField 发生更改时,我收到以下错误:

1. No visible @interface for 'UIButton' declares the selector 'setTitle:'
2. No visible @interface for 'UITextField' declares the selector 'setStringValue:'

所以我假设这与它是 UIButtons 等有关。但是我不确定我将如何以任何其他方式加载问题。

由于错误状态 UIButton 没有任何 setTitle: 实例方法,它只有 setTitle:forState:

UITextField一样没有任何setStringValue:实例方法,要设置文本你可以使用setText:方法。

将您的代码更改为:

[question setText:[QADictionary valueForKey:@"question"]];
[answer1 setTitle:[[QADictionary valueForKey:@"answers"] objectAtIndex:0] forState:UIControlStateNormal];
[answer2 setTitle:[[QADictionary valueForKey:@"answers"] objectAtIndex:1] forState:UIControlStateNormal];
[answer3 setTitle:[[QADictionary valueForKey:@"answers"] objectAtIndex:2] forState:UIControlStateNormal];