這裏是rootviewcontrollerdelegate定義
@protocol RootViewControllerViewDelegate
- (無效)toggleView:(UIViewController中)newController的viewController:(UIViewController中)oldController;
@end
一個可能的實現,以toggleView
-(void)toggleView:(UIViewController *)newController viewController:(UIViewController*)oldController {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([oldController.view superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
[newController viewWillAppear:YES];
[oldController viewWillDisappear:YES];
[oldController.view removeFromSuperview];
[self.view addSubview:newController.view];
[oldController viewDidDisappear:YES];
[newController viewDidAppear:YES];
[UIView commitAnimations];
[oldController release];
}
這將通過翻轉角度
顯然刷卡視圖控制器你必須做出新的RootViewController的地方,並從那裏開始(可能是應用程序代理)
現在,如果你想有一個視圖控制器能夠使用它必須符合協議的RootViewController的,你聲明它的類接口,像這樣
@interface MyViewController : UIViewController <RootViewControllerDelegate> {
id delegate;
}@property(assign) id <RootViewControllerViewDelegate> delegate;
現在你可以使用委託方法交換了看法另一個因爲一切都已經初始化了。代碼交換兩個控制器的觀點可能看起來像這樣
NewViewController *viewController=...
//you can set up your viewControllers data here if you need to
//Since its probable that this view has that data it can just set it instead of
//delegating
viewController.delegate=delegate; //setting up the RootViewController reference
[delegate toggleView:viewController viewController:self];
記得在toggleView回調釋放舊的ViewController,如果你沒有你會得到一個泄漏,因爲你失去所有引用該控制器。
啊這是我如何做到這一點。我有Xcode的一些問題,所以我現在已經解決了。我可以超越Starrt視圖和我自己創建的視圖。我以某種神祕的方式想到,我必須創建一個xib,然後傳遞它(以這種方式,我不能像以前那樣創建一個表)。但你讓我走上了賽場。 – mslot 2009-07-14 21:37:19