【发布时间】:2012-07-15 21:33:53
【问题描述】:
我一直在这里使用 Objective-c 做一件事,但我是这门语言的初学者,这就是我所做的:
有一个名为“firstviewclass”的类,它在我的第一个视图的控制中,在这个视图中有一个用户输入数字的文本字段。文本字段位于名为“setNumber”的 firstviewclass.h 中。还有另一个名为“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
【问题讨论】:
标签: iphone objective-c ios uitextfield uilabel