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. 手写简单IOC

    ReflectUtils.java (反射工具类) package top.icss.ioc; import java.io.File; import java.io.FileFilter; impo ...

  2. 如何使用python图形化界面wxPython

    GUI库主要有三类:tkinter,wxPython和PyQt5,下面主要是针对wxPython的使用说明. 下面的操作均在win10 + pycharm上进行 wxPython的安装: pip in ...

  3. dom&JavaScript&Jquery

    目录 dom&JavaScript&Jquery 建节点 添加节点 删除节点: 替换节点: 属性节点 获取值操作 class的操作 指定CSS操作 操作节点 获取input用户输入 操 ...

  4. Android LinearLayout线性布局详解

    为了更好地管理Android应用的用户界面里的各组件,Android提供了布局管理器.通过使用布局管理器,Android应用图形用户界面具有良好的平台无关性.推荐使用布局管理器来管理组件的分布.大小, ...

  5. Spring03——有关于 Spring AOP 的总结

    本文将为各位带来 Spring 的另一个重点知识点 -- Spring AOP.关注我的公众号「Java面典」,每天 10:24 和你一起了解更多 Java 相关知识点. 什么是 AOP 面向切面编程 ...

  6. Android适配器

    Android适配器 安卓的适配器在我看来是一个非常重要的知识点,面对形式相同但数据源较多的情况时,适配器是一个比较好的解决方法.数据适配器是建立了数据源与控件之间的适配关系,将数据源转换为控件能够显 ...

  7. python之道15

    请实现一个装饰器,限制该函数被调用的频率,如10秒一次(借助于time模块,time.time())(面试题,有点难度,可先做其他) 答案 # 思路 运行不能用 import time def wra ...

  8. Python用户终端输入

    #用户输入,操作 print("python 用户输入操作") # input(提示字符串),函数阻塞程序,并提醒用户输入字符串 instr = input("pleas ...

  9. J. Justifying the Conjecture(规律——整数拆分)

    题目链接 五校友谊赛终于开始了,话不多说A题吧. 从前从前有一个正整数n,你需要找到一个素数x和一个合数y使x+y=n成立,这样就可以双剑合并了. 素数是一个大于1的自然数,它的因数只有1与它自己本身 ...

  10. B. Lost Number【CF交互题 暴力】

    B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...