iOS开发学习之路【UI界面】——UISplitViewController、UIPopoverController

UISplitViewController

创建两个视图控制器,分别为MasterViewController 和 DetailViewController。在AppDelegate中添加。

	self.master = [[MasterViewController alloc]init];
    self.detail = [[DetailViewController alloc]init];
    
    UIScreen *screen = [UIScreen mainScreen];
    self.window = [[UIWindow alloc]initWithFrame:screen.bounds];

    
    UISplitViewController *split = [[UISplitViewController alloc]init];
    split.viewControllers = @[self.master,self.detail];
    split.maximumPrimaryColumnWidth = 200;//设置主列表的最大宽度
    
    self.window.rootViewController = split;
    [self.window makeKeyAndVisible];

iOS开发学习之路【UI界面】——UISplitViewController、UIPopoverController

实现右边的视图内容随着左边的点击事件改变。在 MasterViewController.m 中添加方法。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIApplication *app = [UIApplication sharedApplication];
    AppDelegate *del = app.delegate;
    
    DetailViewController *detail = del.detail;
    
    detail.label.text = [self.dataSource objectAtIndex:indexPath.row];
    
}

UIPopoverController

@property (nonatomic,strong) UIBarButtonItem *item;
@property (nonatomic,strong) UIPopoverController *popover;
@property (nonatomic,strong) ContentViewController *content;
	//添加菜单栏右侧item
	self.item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(show:)];
    self.navigationItem.rightBarButtonItem = self.item;
    
    self.content = [[ContentViewController alloc]init];
    //初始化弹窗
    self.popover = [[UIPopoverController alloc]initWithContentViewController:self.content];
    
    self.popover.popoverContentSize = CGSizeMake(200, 300);
-(IBAction)show:(id)sender{
//    NSLog(@"show...");
    //弹出的位置
    [self.popover presentPopoverFromBarButtonItem:self.item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

iOS开发学习之路【UI界面】——UISplitViewController、UIPopoverController