新建一个子类
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface CCSplit : UISplitViewController
+(instancetype)share;
@end
NS_ASSUME_NONNULL_END
#import "CCSplit.h"
@interface CCSplit ()
@end
@implementation CCSplit
+(instancetype)share{
static CCSplit *instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance=[[CCSplit alloc] init];
});
return instance;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
@end
在建一个左边的viewController 与右边的viewcontroller
左边用来控制,右边用来显示详细信息的
左边的操作,这样就可以实时的显示右边的viewcontroller了
//建一个新的,或者使用已有的来显示在右边
UIViewController *subView=[[CCRightViewController alloc] init];
subView.navigationItem.leftBarButtonItem=[CCSplit share].displayModeButtonItem;
subView.navigationItem.leftItemsSupplementBackButton=YES;
[[CCSplit share] showDetailViewController:[[UINavigationController alloc] initWithRootViewController:subView] sender:nil];
[CCSplit share].preferredDisplayMode=UISplitViewControllerDisplayModeAllVisible;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController=self.splitVC;
[self.window makeKeyAndVisible];
return YES;
}
-(CCLeftViewController *)leftVC{
if (!_leftVC) {
_leftVC=[CCLeftViewController new];
}
return _leftVC;
}
-(CCRightViewController *)rightVC{
if (!_rightVC) {
_rightVC=[[CCRightViewController alloc] init];
}
return _rightVC;
}
-(CCSplit *)splitVC{
if (!_splitVC) {
_splitVC=[CCSplit share];
_splitVC.preferredDisplayMode=UISplitViewControllerDisplayModeAllVisible;
_splitVC.maximumPrimaryColumnWidth=100;
_splitVC.viewControllers=@[self.leftVC,self.rightVC];
}
return _splitVC;
}
网友评论