1

xcode に問題があります。私はobject-cとxcodeの初心者なので...助けてください。

私は2つのViewcontrollersを持っています:ViewController (with .m/.h)そしてHighScores (with .m/.h).

HighScores では、first というラベルを付けました。そしてViewControllerUITextField呼び出された *textField があります。テキストを入力するとき、および既にプレイされたゲームのスコアがラベルに既に存在するテキスト (「最初」) よりも大きい場合、textField のテキストをラベルに表示します。

そう、

これは私のHighScore.hがどのように見えるかです:

#import <UIKit/UIKit.h>

@interface HighScores: UIViewController {

IBOutlet UILabel *first;

}

@end

これはViewController.mです:

#import "ViewController.h"
#import "HighScore.h"

...

NSString *myString = [HighScores.first];

if (score.text > myString) {

    NSString *string = [textField text];
    [HighScores.first setText:string]

UIViewControllerしかし、xcode は、ドット '.' の後に「最初」と入力するとエラーが発生すると言います... xCode に HighScoreの「最初」のラベルを認識させたい場合、どのようにすればよいVewController UiViewControllerですか?

ありがとう!

4

2 に答える 2

2

あなたのコードでは、「最初」は UILabel であり、highScores のビューが読み込まれたときに生成されます。IBOUtletだからです。次に、クラス名でアクセスしようとしています。最初に HighScore クラスのインスタンスを作成してから、「最初に」ラベルにアクセスしてみます。

#import <UIKit/UIKit.h>

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

@end

@implementation HighScores
 - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
{
 self.firstLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
 [self.view addSubview self.firstlabel];
}

@end

ViewController.m よりも

HighScore * highscoreObject = [[HighScore alloc]init];

NSString *mystring = [highscoreObject.firstLabel text];

if (score.text > mystring) {

[highscoreObject.firstLabel setText:score.text];

{
于 2013-03-08T12:10:00.377 に答える
0

ここで混乱している場合は、 notification を使用してみましょう: この場合、IBoutlet も使用できます。設定する文字列を含む通知をスローし、HighScores で通知を読み取り、文字列 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

そしてHighScores.mで

@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];
}
于 2013-03-11T11:05:01.603 に答える