无法访问标签

时间:2012-11-16 22:11:17

标签: iphone ios

我是iPhone开发的初学者,所以我有一个小问题:

这是我的viewcontroller.m

//
//  ViewController.m
//  Conversie talstelsels
//
//  Created by Stijn Hoste on 16/11/12.
//  Copyright (c) 2012 Stijn Hoste. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@synthesize lblOct;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // 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)txtGetal:(id)sender {

  lblOct.text = @"derp";


}
@end

这是我的viewcontroller.h

//
//  ViewController.h
//  Conversie talstelsels
//
//  Created by Stijn Hoste on 16/11/12.
//  Copyright (c) 2012 Stijn Hoste. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
- (IBAction)txtGetal:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *lblDec;
@property (weak, nonatomic) IBOutlet UILabel *lblOct;
@property (weak, nonatomic) IBOutlet UILabel *lblHex;

@end

所以当我尝试这样做时:@synthesize lblOct; 它给我以下错误:非法接口限定符 当我尝试这样做时:lblOct.text = @“derp”; 它给了我这个错误:使用未声明的标识符'lblOct',你的意思是'_lblOct'吗?

有人可以帮我解决这个可能很容易的问题吗?

提前致谢!

2 个答案:

答案 0 :(得分:0)

尝试使用self.lblOct = @"text";

此外,使用新的XCode,您不再需要使用@synthesize,所以只需省略它。

答案 1 :(得分:0)

你应该使用

self.lblOct.text = @"text";
// or
_lblOct.text = @"text";

Xcode 4.4(LLVM 4.0编译器)或更新版本中,如果您不添加@synthesize,Xcode将添加默认值,如

@synthesize variable = _variable;