如何使用数组内容初始化ios中的标签?

时间:2015-12-03 03:02:59

标签: ios objective-c

您好我正在开发一个测验应用程序。当运行应用程序时,我希望标签出现在数组中的问题。我创建了UIlable。我使用的init方法不起作用。我的代码如下:

jQuery("[class^='expand-content-link']").click(function() {
     jQuery(this).next().toggle();
     return false;
}); 

2 个答案:

答案 0 :(得分:0)

您需要将问题的初始化移至awakeFromNib()viewDidLoad(),因为情节提要不使用initWithNibName

答案 1 :(得分:-1)

尝试这样的事情:

       #import "ViewController.h"
    @interface ViewController ()
    @property(nonatomic,assign)int currentQuestionIndex;
    @property(nonatomic,copy)NSArray *questions;
    @property (weak, nonatomic) IBOutlet UILabel *questionLabel;
    @end

    @implementation ViewController



    - (IBAction)showQuestion:(id)sender
    {
        [self showQuestion];
        }

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
self.questions =@[@"Who is the president of US?",@"What is 7 + 7?",@"What is the capital of Vermont?"];

self.currentQuestionIndex= 0;
[self showQuestion];
        }

    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

-(void)showQuestion{
// Step to the next question


        // Get the string at the index in the questions array
        NSString *question = self.questions[self.currentQuestionIndex];

        // Display the string in the question label
        self.questionLabel.text = question;

 self.currentQuestionIndex++;

        // Am I pas the last question?
        if (self.currentQuestionIndex == [self.questions count]) {

            // Go back to the first question
            self.currentQuestionIndex = 0;
        }


}

    @end