iPad拆分视图调用/从另一个视图加载
Posted
技术标签:
【中文标题】iPad拆分视图调用/从另一个视图加载【英文标题】:iPad Split View Call/Load from another view 【发布时间】:2011-09-27 06:29:52 【问题描述】:请帮我解决下面提到的问题。
我的问题是,是否有办法从另一个视图调用拆分视图,比如在我点击一个按钮之后..?
例如,如attached pic 所示,当应用启动时,它会显示第一个屏幕。
当用户点击“点击”按钮时,拆分视图打开。
用户可以执行拆分视图的所有操作,当他按下主页按钮时,他应该回到第一个屏幕。
这可能吗..?我该怎么办呢..?
我是初学者。任何有关代码的帮助将不胜感激..
PS:我曾尝试使用MGSplitView和TOSplitView,但未能实现上述问题的解决方案。
谢谢...
【问题讨论】:
【参考方案1】:检查以下代码。这应该可以轻松帮助您解决问题。
//Intialise the 2 views root and detail
RootViewController * rootVC = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
//To show the nav bar for root, add it into a UINavigationController
UINavigationController * rootVCNav = [[UINavigationController alloc] initWithRootViewController:rootVC];
DetailViewController * detailVC = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
//initialise split view
splitVC = [[UISplitViewController alloc] init];
splitVC.viewControllers = [NSArray arrayWithObjects:rootVCNav,detailVC, nil];
//Tell the split view that its delegate is the detail view.
splitVC.delegate = detailVC;
//tell root that the changes need to be shown on detail view.
rootVC.detailViewController = detailVC;
[rootVC release];
[detailVC release];
[rootVCNav release];
//Here, we get the app delegate object of the project
ProjectAppDelegate * appDel = (ProjectAppDelegate*)[[UIApplication sharedApplication] delegate];
//get window object of the delegate
UIWindow * window1 = [appDel window];
//get the navigation controler of the window of app delegate.
mainNav = [appDel rVC];
//remove the current view from the window.
[mainNav.view removeFromSuperview];
//add the split view to the window
[window1 addSubview:locSplitVC.view];
希望对你有所帮助..
问候, 梅尔文
【讨论】:
【参考方案2】:我做这种类型,但我没有得到拆分视图
(void)viewDidLoad [超级viewDidLoad];
MainViewController *first =[[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
UINavigationController *sec=[[UINavigationController alloc]initWithRootViewController:first];
DetailViewController *detail =[[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil]; UINavigationController *detailv =[[UINavigationController alloc]initWithRootViewController:detail];
UISplitViewController *split =[[UISplitViewController alloc]init];
split.viewControllers=[NSArray arrayWithObjects:sec,detailv, nil];
// split.delegate=detail;
split.delegate =self;
//first.detail=detail;
appDel = (AppDelegate*)[[UIApplication sharedApplication] 委托];
window1 = [appDel 窗口];
UINavigationController *mainNav =[[UINavigationController alloc]init];
mainNav = [appDel 导航]; [mainNav.view removeFromSuperview];
[window1 addSubview:split.view];
// 在从 nib 加载视图后进行任何其他设置。
【讨论】:
以上是关于iPad拆分视图调用/从另一个视图加载的主要内容,如果未能解决你的问题,请参考以下文章
视图完全加载后如何从另一个组件调用方法(AppComponent)?