AJ分享,必须精品

一:效果图

二:注意

对于方法[UIPopoverController dealloc] reached while popover is still visible.
当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;
}

四:全部代码展示

ViewController

#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

#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

最新文章

  1. Fiddler 4 抓包
  2. xamarin.forms 版本自动更新(针对android)
  3. java 15-10 List的三个子类的特点
  4. c/s架构nginx+php-fpm通信原理
  5. winform学习之----将多个控件的click方法绑定到同一click方法中
  6. Apache HTTP Server安装教程
  7. hadoop错误DataXceiver error processing WRITE_BLOCK operation
  8. Matlab聚类分析[转]
  9. 什么时候用spring
  10. 安装_oracle11G_客户端_服务端_链接_oracle
  11. caffe编译报错解决
  12. django中模型详解-字段类型与约束条件
  13. Zookeeper简介与使用
  14. HXY玩卡片(水题测试2017082401&洛谷2192)
  15. [Canvas]RPG游戏雏形 (地图加载,英雄出现并移动)
  16. 属性编辑器,即PropertyEditor-->Spring IoC
  17. 在Ubuntu 12 服务器上源码安装 OpenERP 8.0
  18. 解题报告:poj1321 棋盘问题 - 搜索
  19. day5-re模块
  20. js流程图:aworkflow.js

热门文章

  1. 手把手教你用GoEasy实现Websocket IM聊天
  2. 原创 记录一次线上Mysql慢查询问题排查过程
  3. 《2018面向对象程序设计(java)课程学习进度条》
  4. 5L-链表导论心法
  5. 强化学习之六:Deep Q-Network and Beyond
  6. OpenCV-Python 对极几何 | 五十一
  7. 使用Python中的NLTK和spaCy删除停用词与文本标准化
  8. 旷视6号员工范浩强:高二开始实习,“兼职”读姚班,25岁在CVPR斩获第四个世界第一...
  9. 从零开始编译安装 Extcalc
  10. 前端之jQuery基础篇02-事件