-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
謝謝你,它的工作,但我我以前不理解,標籤和_label只是不同的變量?它是如何工作的?)) – user3370969
我不確定'label'是什麼,以及爲什麼你會得到這個錯誤。通常,你會看到的錯誤是這個變量是未定義的,它也會向你推薦我推薦的兩個中的一個。 – nhgrif