我只是想知道這是否是在iphone/ipad中的不同視圖之間傳遞數據或消息的正確方式。dismissModalViewController在消息在視圖控制器之間傳遞
我有兩個ViewControllers,FirstViewController和SecondViewController。我有一個NSString *消息作爲我的ViewControllers中的一個屬性,我通過以下方式進行設置。
在FirstViewController.h中,我導入了SecondViewController.h類。我有這個IBAction爲被調用,當用戶點擊第一視圖中的按鈕
-(IBAction)ShowSecondView
{
SeondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
secondView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
secondView.message = @"Presented from First View";
[self presentModalViewController:secondView animated:YES];
[secondView release];
}
在我SecondViewController.h,我導入類FirstViewController.h 我有這個IBAction爲被調用,當用戶點擊一個按鈕第二視圖
-(IBAction)GoBack
{
FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:[NSBundle mainBundle]];
firstView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
firstView.message = @"Presented from Second View";
[self presentModalViewController:firstView animated:YES];
[firstView release];
}
的消息被成功地在視圖之間通過,但如果使用以關閉當前視圖控制器返回到在父視圖 [self dismissModalViewController]
,不傳遞該消息。
我的建議是使用委託 – Bonny 2012-02-27 09:53:11