即时新编程,并盯着目标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