我在這裏有一些奇怪的問題,因爲我無法將NSString從一個類傳遞到另一個類。我部署了與其他類相同的方法。將NSString從一個類傳遞到另一個類
我想從secondViewController傳遞一個字符串到我的firstViewController。這就是我所做的。
firstViewController.h
NSString *pickUpAddressString;
@property (nonatomic, retain) NSString *pickUpAddressString;
firstViewController.m
@synthesize pickUpAddressString;
-(void) viewWillAppear:(BOOL)animated {
NSLog(@"pickUpAddressString is %@", pickUpAddressString); // why it's null here?
PickUpAddress.text = pickUpAddressString; // PickUpAddress is a UITextField
}
secondViewController.m
FirstViewController *controller = [[FirstViewController alloc]init];
controller.pickUpAddressString = selectedAddress; // here, I set the string
NSLog(@"selected address :%@\npickUpAddressString:%@", selectedAddress, controller.pickUpAddressString); // I had verified that both strings are valid.
[self.navigationController popViewControllerAnimated:YES]; // pop to firstView
如果你大跌眼鏡回的firstView控制器,這意味着它已經開始。爲什麼用FirstViewController * controller = [[FirstViewController alloc] init]重新啓動它;如果它已經在navigationController棧上準備好了? – Ladislav