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

AJ学IOS 之ipad开发Popover的基本使用的更多相关文章

  1. AJ学IOS 之ipad开发Popover的调色板应用_popover显示后其他控件仍然能进行交互

    AJ分享,必须精品 一:效果 后面的是xcode的控制台 二:代码 ViewController #import "ViewController.h" #import " ...

  2. AJ学IOS 之ipad开发qq空间项目横竖屏幕适配

    AJ分享,必须精品 一:效果图 先看效果 二:结构图 如图所示: 其中用到了UIView+extension分类 Masonry第三方框架做子控制器的适配 NYHomeViewController对应 ...

  3. iOS - 初学iPad开发入门

    iPad是一款苹果公司于2010年发布的平板电脑定位介于苹果的智能手机iPhone和笔记本电脑MacBook产品之间跟iPhone一样,搭载的是iOS操作系统 iPhone和iPad开发的区别 屏幕的 ...

  4. AJ学IOS 之微博项目实战(2)微博主框架-自定义导航控制器NavigationController

    AJ分享,必须精品 一:添加导航控制器 上一篇博客完成了对底部的TabBar的设置,这一章我们完成自定义导航控制器(NYNavigationController). 为啥要做自定义呢,因为为了更好地封 ...

  5. AJ学IOS(13)UI之UITableView学习(下)汽车名牌带右侧索引

    AJ分享,必须精品 先看效果图 代码 ViewController #import "NYViewController.h" #import "NYCarGroup.h& ...

  6. iOS(iPhone,iPad))开发(Objective-C)开发库常用库索引

    http://www.code4app.com 这网站不错,收集各种 iOS App 开发可以用到的代码示例  http://www.cocoacontrols.com/ 英文版本的lib收集  ht ...

  7. AJ学IOS(56)网络基础以及如何搭建服务器

    AJ分享,必须精品 一:为什么要学习网络编程 关于这个问题,为什么要学习网络编程,AJ的理解就是,这东西是时代发展的必要,没什么为什么,就是应该学,除非你就是想玩单机,但是就算是单机也会有购买金币之类 ...

  8. AJ学IOS(55)多线程网络之图片下载框架之SDWebImage

    AJ分享,必须精品 效果: 代码: - (NSArray *)apps { if (!_apps) { NSArray *dictArray = [NSArray arrayWithContentsO ...

  9. AJ学IOS(49)多线程网络之线程的创建NSThreand

    AJ分享,必须精品 一:NSThread的基本使用 1:创建和启动线程 一个NSThread对象就代表一条线程 创建.启动线程 NSThread *thread = [[NSThread alloc] ...

随机推荐

  1. Git&Github入门

    Github: 仓库repository: 存放项目代码,每个项目对应一个项目 收藏star: 收藏 复制克隆项目(Fork): 发起请求Pull Reques: 别人改进你的代码,如果觉得不错可以合 ...

  2. Leetcode_面试题 17.24. 最大子矩阵

    最大子矩阵问题,n是200,枚举上下行,O(N)求一下最大子段和. code class Solution { public: vector<int> getMaxMatrix(vecto ...

  3. 深夜,我用python爬取了整个斗图网站,不服来斗

    QQ.微信斗图总是斗不过,索性直接来爬斗图网,我有整个网站的图,不服来斗. 废话不多说,选取的网站为斗图啦,我们先简单来看一下网站的结构 网页信息 从上面这张图我们可以看出,一页有多套图,这个时候我们 ...

  4. weblogic漏洞练习

    About WebLogic WebLogic是美商Oracle的主要产品之一,系购并得来.是商业市场上主要的Java(J2EE)应用服务器软件(application server)之一,是世界上第 ...

  5. ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory

    问题描述: ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory 首先检 ...

  6. Oracle 11g Windows下安装出现INS-30131错误

    1.错误信息 2.解决方法 问题分析:访问Temp文件夹缺少权限 方案1: 使用net use查看C盘是否共享,否则进行设置,这种方法网上有很多帖子,不详坠 方案2:打开cmd,到相应的解压后的set ...

  7. Spark使用jdbc时的并行度

    Spark SQL支持数据源使用JDBC从其他数据库读取数据. 与使用JdbcRDD相比,应优先使用此功能. 这是因为结果以DataFrame的形式返回,并且可以轻松地在Spark SQL中进行处理或 ...

  8. 将java中Map对象转为有相同属性的类对象(json作为中间转换)

    java中Map对象转为有相同属性的类对象(json作为中间转换) 准备好json转换工具类 public class JsonUtil { private static ObjectMapper o ...

  9. Unix 网络编程卷一源码编译踩坑记录 ubtutu 19.10

    在阅读unpv1时运行源代码的环境配置,这里简单记录一下 源代码里的README 写得挺详细的,但是在Linux 系统的下还没没办法直接编译通过的, 这里我使用的是ubuntu 19.10(在腾讯云1 ...

  10. openssl与java(读取加密码的密钥)

    最近在研究java security方面的东西,java自带可以使用各种加密解密算法(rsa,dsa,des3,aes,md5...),但往往一些密钥是第三方给我们的,我们需要用java装载这些密钥然 ...