RootableviewController.m
#import "RooTableViewCotntroller.h"
#import "AppDelegate.h"
#import "DetailViewController.h"
@interface RooTableViewCotntroller ()
@property(nonatomic,strong)NSArray* imgTitleArr;
@property(nonatomic,strong)NSArray* imgArr;
@end
@implementation RooTableViewCotntroller
- (void)viewDidLoad {
[super viewDidLoad];
self.imgTitleArr = @[@"**",@"**",@"**",@"**",@"**",@"**",@"**"];
NSMutableArray* arr = [[NSMutableArray alloc]init];
for (int i = 1; i <= 7; i++)
{
NSString *imgName = [NSString stringWithFormat:@"car%d.jpg",i];
UIImage* img = [UIImage imageNamed:imgName];
[arr addObject:img];
}
self.imgArr = [arr copy];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.imgArr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
cell.textLabel.text = self.imgTitleArr[indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
DetailViewController *detaiVC = appDelegate.detailVC;
detaiVC.mapView.image = self.imgArr[indexPath.row];
}
DetailViewController.m
#import "DetailViewController.h"
#import "AppDelegate.h"
#import "RooTableViewCotntroller.h"
@interface DetailViewController ()<UIPopoverControllerDelegate>
@end
@implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"主菜单" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
AppDelegate* app = (AppDelegate*)[UIApplication sharedApplication].delegate;
app.spiltVC.displayModeButtonItem.title = @"显示导航栏";
self.navigationItem.leftBarButtonItem = app.spiltVC.displayModeButtonItem;
}
-(void)click:(UIBarButtonItem* )sender
{
RooTableViewCotntroller* rootVC = [[RooTableViewCotntroller alloc]initWithStyle:UITableViewStylePlain];
UIPopoverController* popCtl = [[UIPopoverController alloc]initWithContentViewController:rootVC];
popCtl.popoverContentSize = CGSizeMake(200, 300);
popCtl.backgroundColor = [UIColor yellowColor];
popCtl.delegate = self;
[popCtl presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return YES;
}
-(void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode
{
// 左侧导航栏隐藏
if (displayMode == UISplitViewControllerDisplayModePrimaryHidden)
{
NSLog(@"左侧导航将要隐藏");
AppDelegate *app = (AppDelegate*)[UIApplication sharedApplication].delegate;
app.spiltVC.displayModeButtonItem.title = @"显示导航栏";
//
svc.displayModeButtonItem.title = @"显示导航栏";
self.navigationItem.leftBarButtonItem = app.spiltVC.displayModeButtonItem;
}
else if (displayMode == UISplitViewControllerDisplayModePrimaryOverlay)
{
NSLog(@"左侧导航覆盖到详情视图上");
}
else if (displayMode == UISplitViewControllerDisplayModeAllVisible)
{
NSLog(@"左侧导航全部显示");
self.navigationItem.leftBarButtonItem = nil;
}
else
{
NSLog(@"自动显示");
}
}