即時新編程,並盯着目標c。我想在一個文件中聲明一個屬性,並使其成爲另一個文件,但由於某種原因,它不起作用。我可能在做非常愚蠢的事情,不要怪我。訪問屬性在目標c中形成一個uiviewcontroler實例。
我有folling第一頭:
#import <Foundation/Foundation.h>
#import "second.h"
@interface ViewController : UIViewController{
NSString* theText;
}
@property (nonatomic, assign) IBOutlet UITextField *textField;
@property (nonatomic, retain) NSString *theText;
@end
在這裏,我.m文件
#import "ViewController.h"
@implementation ViewController
@synthesize theText,textField;
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self setTheText:textField.text];
}
@end
現在我想用theText財產在其他文件中既使用它,並改變它。所以我想這會工作,但它並不:
第二.m文件:
#import "second.h"
#import "ViewController.h"
@implementation second
@synthesize secLabel;
-(void)nameLabel{
secLabel.text = [ViewController theText];
}
@end
編譯器說,對選擇沒有已知的類方法。我嘗試了很多,但沒有任何工作,有人知道如何使這項工作?
TNX
謝謝! 我明白教導,但我不明白在哪裏/如何打電話: MyManager * sharedManager = [MyManager sharedManager]; 你能解釋一下嗎? – user1022722
它在執行任何命令訪問單例類之前必須執行的操作。所以E.G. – Necro
如果你在按下按鈕後改變一個數字,你會像這樣寫MyManager * sharedManager = [MyManager sharedManager]; sharedManager.number + = 1;得到它? – Necro