UIPopOverController的使用问题
2016-05-26 14:39
447 查看
crash的原因如下:
'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.'
所以必须使用ipad进行浏览,
所以在代码中使用UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
所以在viewDidLoad的代码如下:
[cpp] view plaincopy
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
container.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:container];
UIButton *tmpButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 50, 100, 50)];
tmpButton.backgroundColor = [UIColor brownColor];
[tmpButton setTitle:@"点击显示" forState:UIButtonTypeCustom];
[tmpButton addTarget:self action:@selector(btnTest:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tmpButton];
[tmpButton release];
popTableView = [[PopTableViewController alloc] init];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
popOverController = [[UIPopoverController alloc] initWithContentViewController:popTableView];
popOverController.delegate = self;
popOverController.popoverContentSize = CGSizeMake(100, 300);
}
}
在btnTest方法中实现popOverController显示
代码如下:
[cpp] view plaincopy
-(void)btnTest:(UIButton *)sender
{
CGRect presentFromRect = CGRectMake(sender.frame.origin.x, sender.frame.origin.y, sender.frame.size.width, sender.frame.size.height);
[popOverController presentPopoverFromRect:presentFromRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
现在可以使用ipad运行下显示了。在iphone模拟器中不会出现crash,但是不会弹出popOverController,显示不出需要的效果
相关文章推荐
- 轻量web服务器开发日记06-request结构体的实现
- 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件
- 从svn下载项目后build path替灰色,应该如何解决呢?
- iOS开发之高级视图—— UINavigationController(一)简单导航功能实现
- UINavgationController中覆写preferredStatusBarStyle方法不执行的问题
- 如何写好一个UITableView(完整版)
- 13周练 F - Infinite Sequence 【数列性质】
- ubuntu MiniGUI移植
- 相当便利的UI交互演示工具
- requireJs和r.js压缩工具
- 配置DruidDataSource参考(com.alibaba.druid.pool.DruidDataSource)
- an internal error occurred during building workspace 错误
- CodeForces 675 A Infinite Sequence
- 207. Course Schedule My SubmissionsQuestionEditorial Solution【M】【48】【vip】【再来一遍】
- error: .pch/release-shared-emb-arm/QtGui: No such file or directory compilation terminated.
- 【CodeForces】675A - Infinite Sequence(易错)
- UICollectionView一个section只有一个item的时候它会出现在屏幕中间的bug
- UICollectionView如果在数据不够一屏时上下滚动
- jenkins xcodebuild命令行打包iOS项目问题汇总
- @RequestParam @RequestBody @PathVariable 等参数绑定注脚详解