开发者

Objective-c Novice needs help - UIView controller

i have created some uiviews (view1 and view2) and in my MainView implementation file i set the text of labels for labels in those views, but they are not showing. Do i need to reference that particular uiview somehow, or how do i do this?

Here is what i have got, but at the minute no text is showing on my labels or buttons. Here is my code:

-(IBAction)lvl1Next{

    switch (questionNum)
    {
        case开发者_如何学JAVA 0:
            [lvl1ButtonA setTitle:@"A: 372" forState: UIControlStateNormal];
            [lvl1ButtonB setTitle:@"B: 376" forState: UIControlStateNormal];
            [lvl1ButtonC setTitle:@"C: 374" forState: UIControlStateNormal];
            [lvl1LabelQuestion setText:(@"1. 139 + 235 =")];
            answer=@"3";
            break;
        case 1:
                 .....

Anyone know why my labels are not showing? When i try:

[view2.lvl1ButtonA setTitle:@"A: 372" forState: UIControlStateNormal];

I get an error: "request for member not a structure or union".


You reference UILabels and UIButtons through outlets, or programmatically by adding them to UIViews. You've produced no evidence of having done either of those two things in the question above.

The error on this line of code, indicates that you are not familiar with adding UIButtons to UIViews, or referencing UIButtons once the are added to views.

[view2.lvl1ButtonA setTitle:@"A: 372" forState: UIControlStateNormal];

You can't access a UIButton this way. To reference an object (button or label) added using IB. You would specify an IBOutlet in your .h file like so:

IBOutlet UIButton *lvl1ButtonA;

I'll let you search StackOverflow for the code to add a UIButton or UILabel to a view via code.

Anyhoo, to answer your question, check (or search) how to add UIButton or UILabel to UIView via code and via Interface Builder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜