2012-11-16 79 views
1

我在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'吗?

有人可以帮我解决这个问题吗?

在此先感谢!

+1

你不应该在界面中“@综合”一个属性 - 将其移入实现中。 – 2012-11-16 22:13:20

+0

将'@ synthesize'移入'@ implementation'。 –

+0

当你没有'@ synthesize'时,最新的Xcode会提供一个,但它会将你的“xxxx”属性与实例变量“_xxxx”关联起来。 (而@synthesize xxxx;'关联属性“xxxx”与实例变量“xxxx”。)这解释了你的第二个错误信息。 –

回答

0

您应该使用

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

Xcode 4.4(LLVM编译器4.0)或更新的版本,如果你不添加@synthesize Xcode的将添加默认一个像

@synthesize variable = _variable; 
+0

谢谢你所有的答案!这个解决了我的问题。快乐的编码! –

+0

@StijnHoste那么,你能接受我的答案,因为这解决了你的问题?谢谢!我喜欢我的回答被投票的感觉。 – sunkehappy

0

使用self.lblOct = @"text";

此外,随着新的XCode尝试,你不需要使用@synthesize了,所以就忽略它。