Xcode 如何将UILabel从一个UIViewcontroller导入到另一个UIViewcontroller

Xcode 如何将UILabel从一个UIViewcontroller导入到另一个UIViewcontroller,xcode,uiviewcontroller,uilabel,textfield,Xcode,Uiviewcontroller,Uilabel,Textfield,我的xcode有问题。 我是一个有object-c和xcode的noob所以。。。请帮忙 我有两个视图控制器:ViewController(带.m/.h)和HighScores(带.m/.h)。 在HighScores中,我贴上了一个名为first的标签。在ViewController中,我有一个名为*textField的UITextField。当我输入文本并且已经玩过的游戏的分数比标签中已经存在的文本(第一个)更高时,我希望文本字段中的文本出现在标签中 所以 这就是我的HighScore.h的

我的xcode有问题。 我是一个有object-c和xcode的noob所以。。。请帮忙

我有两个视图控制器:
ViewController(带.m/.h)
HighScores(带.m/.h)。

在HighScores中,我贴上了一个名为first的标签。在
ViewController
中,我有一个名为*textField的
UITextField
。当我输入文本并且已经玩过的游戏的分数比标签中已经存在的文本(第一个)更高时,我希望文本字段中的文本出现在标签中

所以

这就是我的HighScore.h的样子:

#import <UIKit/UIKit.h>

@interface HighScores: UIViewController {

IBOutlet UILabel *first;

}

@end
但是xcode说当我在点“”之后键入“first”时出现错误。。。如果我想让xCode在
VewController
UIViewController
中识别HighScore
UIViewController
中的“第一个”标签,我该怎么做

谢谢

在您的代码中,“first”是一个UILabel,它将在加载高分视图时生成。 因为它是一个出口。 其次,您正在尝试使用类名进行访问。 首先创建HighScore类的实例,然后尝试访问标签“first”


如果您对此感到困惑,请使用通知: 在这种情况下,您也可以使用IBoutlet。 我们将抛出一个带有要设置的字符串的通知,以高分读取通知,并使用字符串send设置标签

在ViewController.m中

if (score.text > myString) {

NSString *string = [textField text];

[[NSNotificationCenter defaultCenter] postNotificationName:@"update" object:string];
}

@interface HighScores: UIViewController
@property (nonatomic , strong) IBOutlet  UILabel *firstLabel  ;

@end
高分

@implementation HighScores

- (void)viewDidLoad
{
 [super viewDidLoad];

[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changetext:) name:@"update" object:nil]; 

}

- (void) changetext:(NSNotification *)notification {
 NSLog(@"Received"); 
   self.firstLabel.text = [notification object];
}

六羟甲基三聚氰胺六甲醚。。。如何创建该类的实例?你能给我看一下密码吗?谢谢谢谢现在xCode识别了标签,但我还有一个问题。。。我希望UILabel中的文本在分数为新的高分时更改。我的代码看起来是正确的,但当我运行并播放它时,我的UILabel并没有改变。。。我已经对代码进行了一些编辑。对于第二个问题,如果实例相同,它将更改。两个控制器应处于已分配状态,然后将HighScore的相同实例传递给另一个控制器,并更改标签的文本。。这取决于应用程序的层次结构。好的!非常感谢你!我可以投票给它,因为我没有15个声誉:但我把它标为正确!我希望你也能得到第二个问题的答案我不知道我做错了什么:S我对objective-c编程非常陌生。。。。这里有一个我的项目视频。。。如果你想看,你可以看更多的信息:(谢谢你或你的努力。)。!
HighScore * highscoreObject = [[HighScore alloc]init];

NSString *mystring = [highscoreObject.firstLabel text];

if (score.text > mystring) {

[highscoreObject.firstLabel setText:score.text];

{
if (score.text > myString) {

NSString *string = [textField text];

[[NSNotificationCenter defaultCenter] postNotificationName:@"update" object:string];
}

@interface HighScores: UIViewController
@property (nonatomic , strong) IBOutlet  UILabel *firstLabel  ;

@end
@implementation HighScores

- (void)viewDidLoad
{
 [super viewDidLoad];

[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changetext:) name:@"update" object:nil]; 

}

- (void) changetext:(NSNotification *)notification {
 NSLog(@"Received"); 
   self.firstLabel.text = [notification object];
}