AJ学IOS 之ipad开发Popover的基本使用
2015-11-29 00:45
274 查看
AJ分享,必须精品
当popover还在显示的时候,它就挂了
不允许popover还在显示的时候挂掉
popover必须在消失的时候挂掉
一:效果图
二:注意
对于方法[UIPopoverController dealloc] reached while popover is still visible.当popover还在显示的时候,它就挂了
不允许popover还在显示的时候挂掉
popover必须在消失的时候挂掉
三:核心代码
[code]- (IBAction)popMenu:(id)item { // 0.内容 MenuViewController *menu = [[MenuViewController alloc] init]; // 1.创建一个UIPopover UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]]; // 2.设置尺寸 // popover.popoverContentSize = CGSizeMake(320, 44 * 5); // 3.从哪里显示出来 --> 指向item [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; self.popover = popover; }
四:全部代码展示
ViewController
[code]#import "ViewController.h" #import "MenuViewController.h" @interface ViewController () - (IBAction)popMenu:(id)item; @property (nonatomic, strong) UIPopoverController *popover; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } // -[UIPopoverController dealloc] reached while popover is still visible. // 当popover还在显示的时候,它就挂了 // 不允许popover还在显示的时候挂掉 // popover必须在消失的时候挂掉 /** * 弹出Popover菜单 */ - (IBAction)popMenu:(id)item { // 0.内容 MenuViewController *menu = [[MenuViewController alloc] init]; // 1.创建一个UIPopover UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]]; // 2.设置尺寸 // popover.popoverContentSize = CGSizeMake(320, 44 * 5); // 3.从哪里显示出来 --> 指向item [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; self.popover = popover; } @end
MenuViewController
[code]#import "MenuViewController.h" @interface MenuViewController () @property (nonatomic, strong) NSArray *titles; @end @implementation MenuViewController - (void)viewDidLoad { [super viewDidLoad]; self.titles = @[@"设置", @"清除缓存", @"退出", @"基本信息"]; self.title = @"菜单"; self.view.backgroundColor = [UIColor blueColor]; CGFloat w = 320; CGFloat h = self.titles.count * 44; self.preferredContentSize = CGSizeMake(w, h); // self.contentSizeForViewInPopover = CGSizeMake(w, h); } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.titles.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } cell.textLabel.text = self.titles[indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UIViewController *vc = [[UIViewController alloc] init]; vc.view.backgroundColor = [UIColor redColor]; [self.navigationController pushViewController:vc animated:YES]; } @end
相关文章推荐
- AJ学IOS 之ipad开发qq空间项目横竖屏幕适配
- AJ学IOS 之二维码学习,快速打开相机读取二维码
- AJ学IOS 之二维码学习,快速生成二维码
- AJ学IOS 之tableView的下拉放大图片的方法
- AJ学IOS 之BLOCK的妙用_利用block实现链式编程
- AJ学IOS 之微博项目实战(13)发送微博调用相机里面的图片以及调用相机
- AJ学IOS 之微博项目实战(12)发送微博自定义工具条代理实现点击事件
- AJ学IOS 之微博项目实战(11)发送微博自定义TextView实现带占位文字
- AJ学IOS 之微博项目实战(10)微博cell中图片的显示以及各种填充模式简介
- AJ学IOS 之微博项目实战(9)微博模型之时间相关重要操作,判断刚刚,昨天,今年等等
- AJ学IOS 之控制器view显示中view的父子关系及controller的父子关系_解决屏幕旋转不能传递事件问题
- AJ学IOS 之CoreLocation反地理编码小Demo输入经纬度得到城市
- AJ学IOS 之CoreLocation地理编码小Demo输入城市得到经纬度
- AJ学IOS 之CoreLocation指南针小应用
- AJ学IOS 之CoreLocation基本使用
- AJ学IOS 之第一次打开Xcode_git配置,git简单学习
- AJ学IOS 之微博项目实战(8)用AFNetworking和SDWebImage简单加载微博数据
- AJ学IOS 之微博项目实战(6)导航控制器NavigationController 的滑动回退功能实现
- AJ学IOS 之微博项目实战(5)微博自定义搜索框searchBar
- AJ学IOS 之微博项目实战(4)微博自定义tabBar中间的添加按钮