Я определил UITextField в моем firstViewController следующим образом:
// 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;
}
Затем я попытался восстановить его в своем втором ViewController во время viewWillAppear.
- (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";
Могу ли я узнать разницу между этим подходом и вашим? Я вижу, чтоrelease
иretain
используются, и это меня смутило. 27.08.2011