2012-11-16 138 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了,所以就忽略它。