必须使用“struct”标签来引用“label”类型

时间:2014-03-02 15:09:05

标签: objective-c

我收到错误必须使用'struct'标签来引用'label'类型 什么不对?我用注释标记出现错误。我的Xcode版本是5.0.2 ////////////////////////////////////////////////// ///////////////////////////////////////////// .M

  #import "GameViewController.h"

@interface GameViewController ()

@end

@implementation GameViewController

-(void)generate{
    int a=1+arc4random() % 9;
    int b=1+arc4random() % 9;

    int sum=a+b;
    label.text = [NSString stringWithFormat:@"%d + %d = ", a, b]; //here is error
    label.tag=sum;  //and here

}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self generate];
    // Do any additional setup after loading the view, typically from a nib.
}

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

- (IBAction)submit:(id)sender {
    int num=[_answer.text intValue];
    UIAlertView *alert;
    if(num == _label.tag){
        alert=[[UIAlertView alloc]initWithTitle:@"Correct" message:@"Let's try another one!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        alert.tag =1;
    }else{
        alert =[[UIAlertView alloc]initWithTitle:@"Wrong!" message:@"That answer is incorrect" delegate:self cancelButtonTitle:@"Try again" otherButtonTitles:nil, nil];
    }
    [alert show];
}

@end

·H

#import <UIKit/UIKit.h>

@interface GameViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextField *answer;

- (IBAction)submit:(id)sender;
@end

1 个答案:

答案 0 :(得分:2)

尝试self.label.text_label.text