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

本文深入探讨了iOS开发中的UISplitViewController和UIPopoverController。通过创建MasterViewController和DetailViewController,展示了如何在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];

在这里插入图片描述

实现右边的视图内容随着左边的点击事件改变。在 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];
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值