2014-03-02 49 views
-1

我得到了一个错误必须使用'结构'标签来引用'标签'类型 什么是不正确?我标记了出现错误的注释。我的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 

回答

2

尝试self.label.text_label.text

+0

谢谢你,它的工作,但我我以前不理解,标签和_label只是不同的变量?它是如何工作的?)) – user3370969

+0

我不确定'label'是什么,以及为什么你会得到这个错误。通常,你会看到的错误是这个变量是未定义的,它也会向你推荐我推荐的两个中的一个。 – nhgrif