猫猫分享,必须精品
原创文章,欢迎转载。转载请注明:翟乃玉的博客
地址:http://blog.csdn.net/u013357243
对于方法[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;
}
#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
#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
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u013357243/article/details/49245779