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

时间:2015-01-03 09:01:03

标签: ios objective-c uibutton uitextfield

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

我有一个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应用程序上正常工作。

然而,现在当更改tu UIButtons和UITextField时,我会收到以下错误:

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

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

1 个答案:

答案 0 :(得分:3)

由于错误状态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];