app.h
@class ViewController;@class DetailViewController;@interface AppDelegate : UIResponder@property (strong, nonatomic) UIWindow *window;
@property(nonatomic,strong)ViewController *rootVC;
@property(nonatomic,strong)DetailViewController *detailVC;
@property(nonatomic,strong)UISplitViewController *splitVC;
app.m
#import "ViewController.h"
#import "DetailViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.rootVC = [[ViewController alloc]initWithStyle:UITableViewStylePlain ];
self.rootVC.navigationItem.title = @"导航视图";
UINavigationController *rootNav = [[UINavigationController alloc]initWithRootViewController:self.rootVC];
self.detailVC = [[DetailViewController alloc]init];
self.detailVC.navigationItem.title = @"详情";
UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:self.detailVC];
self.splitVC = [[UISplitViewController alloc]init];
self.splitVC.viewControllers = @[rootNav,detailNav];
self.splitVC.delegate = self.detailVC;
self.window.rootViewController = self.splitVC;
return YES;
ViewController.m
#import "AppDelegate.h"
@interface ViewController ()
{
NSArray *_arr;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_arr = @[@"1",@"2",@"3"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *str = @"str";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];
}
cell.textLabel.text = _arr[indexPath.row];
return cell;
}
DetailViewController.h
@interface DetailViewController : UIViewController
DetailViewController.m
#import "AppDelegate.h"
#import "ViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"主菜单" style:UIBarButtonItemStylePlain target:self action:@selector(showPopOverController:)];
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
app.splitVC.displayModeButtonItem.title = @"显示导航栏";
self.navigationItem.leftBarButtonItem = app.splitVC.displayModeButtonItem;
}
-(void)showPopOverController:(UIBarButtonItem *)sender
{
ViewController *rootVC = [[ViewController alloc]initWithStyle:UITableViewStylePlain];
UIPopoverController *popCtl = [[UIPopoverController alloc]initWithContentViewController:rootVC];
popCtl.popoverContentSize = CGSizeMake(200, 300);
popCtl.backgroundColor = [UIColor clearColor];
popCtl.delegate = self;
[popCtl presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}