Objective c 必须使用;结构";标签指的是“类型”;标签";
我遇到一个错误,必须使用“struct”标记引用类型“label” 什么是不正确的??我在出现错误的地方用注释标记。我的Xcode版本是5.0.2 /////////////////////////////////////////////////////////////////////////////////////////////// m hObjective c 必须使用;结构";标签指的是“类型”;标签";,objective-c,Objective C,我遇到一个错误,必须使用“struct”标记引用类型“label” 什么是不正确的??我在出现错误的地方用注释标记。我的Xcode版本是5.0.2 /////////////////////////////////////////////////////////////////////////////////////////////// m h #导入 @界面GameViewController:UIViewController @属性(弱,非原子)IBUILabel*标签; @属性(弱,非原子
#导入
@界面GameViewController:UIViewController
@属性(弱,非原子)IBUILabel*标签;
@属性(弱,非原子)IBUITEXTFIELD*答案;
-(iAction)提交:(id)发件人;
@结束
试试self.label.text
或\u label.text
谢谢,它奏效了,但我不明白,label和\u label只是不同的变量?它是如何工作的?)我不确定标签是什么,以及为什么会出现这种错误。通常,您会看到的错误是这个变量未定义,它也会向您推荐我推荐的两个变量之一。
#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
#import <UIKit/UIKit.h>
@interface GameViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextField *answer;
- (IBAction)submit:(id)sender;
@end