私はここでobjective-cを使用して何かをしてきましたが、私はこの言語の初心者であり、それが私がしたことです:
私の最初のビューの制御下にある「firstviewclass」という名前のクラスがあります。このビューには、ユーザーが数字を入力するテキストフィールドがあります。テキストフィールドは、「setNumber」という名前の firstviewclass.h にあります。2番目のビューを制御する「secondviewclass」という名前の別のクラスがあり、このビューにはsecondviewclass.hにあるラベルがあり、ユーザーがテキストフィールドに入力した値をこのラベルに受け取るようにしたい最初のビューですが、iOSシミュレーターでテストすると、テキストフィールドに入力した数字がラベルに0として表示されます...どうしたらいいのか本当にわかりません!
私のコード:
firstviewclass.h:
#import <UIKit/UIKit.h>
@interface firstviewclass : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *setNumber;
- (IBAction)gotonextview:(id)sender;
@end
secondviewclass.h:
#import <UIKit/UIKit.h>
#import "firstviewclass.h"
@interface secondviewclass : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *labelthatrecivesthetextfieldvalue;
@end
secondviewclass.m:
#import "secondviewclass.h"
#import "firstviewclass.h"
@implementation secondviewclass
@synthesize labelthatrecivesthetextfieldvalue;
-(void)viewDidLoad{
[super viewDidLoad];
firstviewclass *object = [[firstviewclass alloc] init];
NSString *string = [[NSString alloc] initWithFormat:@"%i", [object.setNumber.text intValue]];
labelthatrecivesthetextfieldvalue.text = string;
}
@end