0

UILabel *employeeNumLabelFirstviewcontroller クラスに があります。次に、そのラベルのテキストを secondviewcontroller クラスのメソッドから変更したいと思います。Secondviewcontroller クラスに次のコードを追加しました。

-(IBAction)save:(id)sender{
 number ++;

 NSString * numberString = [NSString stringWithFormat:@"%d",number];

 [employeeNumLabel setText:numberString]; 
}

しかし、エラーが表示されています: use of undeclared identifier employeeNumLabel。Firstviewcontroller.h を Secondviewcontroller.m クラスにインポートしましたが。

4

4 に答える 4

1

Firstviewcontroller の @implementaion の下に UILabel *employeeNumLabel を宣言します。

@implementation Firstviewcontroller
 UILabel *employeeNumLabel;

次に、次のようにsecondviewcontrollerでexternします

 @implementation secondviewcontroller
 extern UILabel *employeeNumLabel;

その後、コードを使用してください。

于 2012-07-05T07:21:55.353 に答える
0

Firstviewcontroller.hで、employeeNumLabelをexternとして宣言します。

  @interface Firstviewcontroller : UIViewController{}
      extern  UILabel *employeeNumLabel;

次に、Firstviewcontroller.m(グローバル変数が宣言されている@place)に以下を追加します。

UILabel *employeeNumLabel; 

次に、Firstviewcontroller.hをsecondviewcontroller.hにインポートしてから、コードを使用します。

于 2012-07-05T07:39:09.610 に答える
0

ヘッダーでラベルを定義します

@property (nonatomic, retain) UILable * employeeNumLabel;

.m ファイルで合成します

@synthesize employeeNumLabel

init 関数で、メモリをラベルに割り当て、それをビューに追加します。または、IBOutlet を作成して、このラベルにリンクすることもできます。

于 2012-07-05T07:22:14.137 に答える
0

ラベルのテキストを変更するには、次のことを行う必要があります..

1)Label In first view Controllerのプロパティを作成する必要があります...

2)ラベルにアクセスして同じオブジェクトのテキストを設定できるように、2番目のView Controllerで最初のView Controllerの共有参照が必要です。

または .. もう 1 つ実行してください..

1) NSString *lblString を取得します。あなたのappdelegateクラスで、そのプロパティを作成します..

2)次のコードを使用して、アプリケーション全体で appdelegate の共有参照を取得できることを知っています

[[UIApplication sharedApplication] delegate]; //this will give your appdelegate Object..

3) 次に、secondViewController クラス メソッドで...

Your_Appdelegate *appdelegate = (Appdelegate *)[[UIApplication sharedApplication] delegate];
appdelgate.lblString = @"YOUR_LABEL_TEXT";

4)そしてFirstViewControllerで..同じ方法でlableTextを設定します...

 Your_Appdelegate *appdelegate = (Appdelegate *)[[UIApplication sharedApplication] delegate];
yourLabel.text = appdelgate.lblString;

最初に、ラベルに必要なテキストを appdelegate に設定します。

これがあなたの助けになりますように...

于 2012-07-05T07:26:44.123 に答える