http://forums.macrumors.com/showthread.php?t=1091071
Just wondering if anybody has managed to get the MGSplitViewController ( http://mattgemmell.com/2010/08/03/mg...roller-updated) working with a NavigationController in the details side?
|
http://stackoverflow.com/questions/6227106/changing-views-with-mgsplitview-controller
You're just creating new view controllers. You're not adding them anywhere. You add view controllers to the split view controller by using its viewControllers
property.
EDIT: I've used MGSplitViewController
, but I never tried to change the detail view like that. I just pushed the new detail view controller onto the navigation controller.
I am afraid that we have to use popover or alert or action sheet....
事实证明只是我们缺乏一点耐心去看 mgsplit的实现,以及现在的sample提供的xib设计后,反而导致了一点问题:)
有几个需要说明的地方:
1. 最简单的想法,自己定义一个navigationcontroller,然后去用不久可以了么,失败!,因为 在初始化就会产生问题,UInavigationcontroller理论上必须是root的
2. 那么在detail xib 中加入navigationcontroller,把view拖进去,包括设置 view root那个什么class为detailviewcontroller ,还是失败,这个应该是可以继续看的,,应该有解
3. 用最原始的方法关联navigationcontroller view
UINavigationController *root=[[UINavigationController alloc] initWithRootViewController:rootViewController];
UINavigationController *detail=[[UINavigationController alloc] initWithRootViewController:detailViewController];
detail.navigationBar.hidden=YES;
[detail retain];
//invokes a method of the receiver on the current thread using the default mode after a delay.
[rootViewController performSelector:@selector(selectFirstRow) withObject:nil afterDelay:0];
[detailViewController performSelector:@selector(configureView) withObject:nil afterDelay:0];
self.splitViewController.viewControllers=[[NSArray alloc] initWithObjects:root,detail, nil];
[root release];
[detail release];
4. 由于那个detail view要动态切换,就需要把这个调整背景布局的代码放到 root的rotation event handler里面去
/*
if( [UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortrait||[UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
splitController.splitPosition=320.0f;
splitController.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed: @"backgroundS.png"]];
}
else {
splitController.splitPosition=500.0f;
splitController.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed: @"backgroundD.jpg"]];
}
*/
好,基本上这样就实现了detail带navigation的mgsplitview的用法了
https://github.com/slatvick/APSplitViewController
Have a look at APSplitViewController.
//read me about MPSPlitView
MGSplitViewController
=====================
MGSplitViewController is a replacement for UISplitViewController, with various useful enhancements.
Donations
---------
I wrote MGSplitViewController for my own use, but I'm making it available (as usual) for the benefit of the iOS developer community.
If you find it useful, a Paypal donation (or something from my Amazon.co.uk Wishlist) would be very much appreciated. Appropriate links can be found here: <http://mattgemmell.com/source>
Features
--------
Please note that, since split-views are commonly used for "Master-Detail" interfaces, I call the first sub-view the "master" and the second sub-view the "detail".
- By default, MGSplitViewController mimics the appearance and (complete) behaviour of UISplitViewController, including its delegate API. It accepts two UIViewControllers (or subclasses thereof).
- Allows toggling the _visibility of the master view_ in either interface-orientation; i.e. you can have master-detail or detail-only in either landscape and/or portrait orientations (independently, and/or interactively).
- Allows choosing whether the _split orientation_ is vertical (i.e. left/right, like UISplitViewController), or horizontal (master above, and detail below). You can toggle between modes interactively, with animation.
- Allows choosing whether the master view is _before_ (above, or to left of) the detail view, or _after_ it (below, or to the right).
- Allows you to choose (and change) the _position_ of the split, i.e. the relative sizes of the master and detail views.
- Allows you to enable _dragging_ of the split/divider between the master and detail views, with optional constraining via a delegate method.
- Allows you to choose the _width of the split_ between the master and detail views.
- Preset "_divider styles_": one for non-draggable UISplitViewController-like dividers, and one for draggable, thicker style with a grip-strip.
- Allows you to substitute your own divider-view (an MGSplitDividerView subclass), used to draw the split between the master and detail views.
How to use
----------
The "MGSplitViewController.h" header file (and the sample project) should be self-explanatory. It's recommended that you use the project as a reference.
Interface Builder support
-------------------------
At time of writing, MGSplitViewController cannot be quite as elegantly _visually_ configured like UISplitViewController using Interface Builder.
You can, however, (and it is recommended that you do) create an instance of it in a xib, and connect the masterViewController and detailViewController outlets to the required view-controllers.
License and Warranty
--------------------
The license for the code is included with the project; it's basically a BSD license with attribution.
You're welcome to use it in commercial, closed-source, open source, free or any other kind of software, as long as you credit me appropriately.
The MGSplitViewController code comes with no warranty of any kind. I hope it'll be useful to you (it certainly is to me), but I make no guarantees regarding its functionality or otherwise.
Support / Contact / Bugs / Features
-----------------------------------
I can't answer any questions about how to use the code, but I always welcome emails telling me that you're using it, or just saying thanks.
If you create an app which uses the code, I'd also love to hear about it. You can find my contact details on my web site, listed below.
Likewise, if you want to submit a feature request or bug report, feel free to get in touch. Better yet, fork the code and implement the feature/fix yourself, then submit a pull request.
Enjoy the code!
Cheers,
Matt Legend Gemmell
Writing: http://mattgemmell.com/
Contact: http://mattgemmell.com/about
Twitter: http://twitter.com/mattgemmell
Hire Me: http://instinctivecode.com/