Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 必须使用;结构";标签指的是“类型”;标签";_Objective C - Fatal编程技术网

Objective c 必须使用;结构";标签指的是“类型”;标签";

Objective c 必须使用;结构";标签指的是“类型”;标签";,objective-c,Objective C,我遇到一个错误,必须使用“struct”标记引用类型“label” 什么是不正确的??我在出现错误的地方用注释标记。我的Xcode版本是5.0.2 /////////////////////////////////////////////////////////////////////////////////////////////// m h #导入 @界面GameViewController:UIViewController @属性(弱,非原子)IBUILabel*标签; @属性(弱,非原子

我遇到一个错误,必须使用“struct”标记引用类型“label” 什么是不正确的??我在出现错误的地方用注释标记。我的Xcode版本是5.0.2 /////////////////////////////////////////////////////////////////////////////////////////////// m

h

#导入
@界面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