我在我的firstViewController定义为UITextField如下传的UITextField文本从一个视图到另一个
// firstViewController.h
IBOutlet UITextField *PickUpAddress
@property (nonatomic, retain) UITextField *PickUpAddress;
//firstViewController.m
@synthesize PickUpAddress;
// Push secondView when the 'Done' keyboard button is pressed
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
if (textField == PickUpAddress) {
SecondViewController *secondViewController= [[SecondViewController alloc]
initWithNibName:@"SecondViewController"
bundle:nil];
secondViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];
}
return NO;
}
然后我试图viewWillAppear中
期间以检索它在我secondViewController- (void)viewWillAppear:(BOOL)animated {
BookingViewController *bookingViewController = [[BookingViewController alloc] init];
NSString *addressString = [[NSString alloc] init];
addressString = bookingViewController.PickUpAddress.text;
NSLog(@"addressString is %@", bookingViewController.PickUpAddress.text);
}
但它返回在我的控制台上为NULL。为什么? 在此先感谢:)
您的解决方案确实有效,但为什么我们需要使用方法来设置字符串?我们可以只用'@synthesize myString'并设置属性,'secondViewController.myString = @“stringToSet”;'我可以知道这种方法与你的区别吗?我看到'释放'&'保留'被使用,并使我困惑。 –
我认为我的方法与你的方法 – davartan
@MaTaKazer没有什么区别,如果Davartan给你解决方案,请投票。 – azizbekian