UIPopoverController具体解释
今天一位童鞋问我个问题。大意是popoverController不会显示。经过我寻找问题发现以下这种方法不好掌控。
为什么说他不好掌控那。我这个给大家带来一个列子。通过这个列子来介绍PopoverController的具体使用方法,以及这种方法的2中传參技巧。
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;
方案1:新建一个view,在这个view上加入手势来监听PopoverController的弹出。
监听方法例如以下:
- (IBAction)tapClick:(UITapGestureRecognizer *)sender {
ColorViewController *color = [[ColorViewController alloc]init]; _pc = [[UIPopoverController alloc] initWithContentViewController:color];
_pc.popoverContentSize = CGSizeMake(320, 480); [_pc presentPopoverFromRect:sender.view.bounds inView:sender.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
请大家细致看:这里的sender仅仅是一个手势。
上面的sender.view是谁?就是手势被加入的视图。fromRect这个传的就是手势被加入的到哪个视图就传哪个视图。后边的inview意思就是popover在哪个视图?当然是在手势被加入的视图了。
方案2:新建一个button,在这个button上加入手势来监听PopoverController的弹出
- (IBAction)btnClick:(UIButton *)sender
{
ColorTableViewController *color = [[ColorTableViewController alloc]init]; _pc = [[UIPopoverController alloc] initWithContentViewController:color];
_pc.popoverContentSize = CGSizeMake(320, 480); [_pc presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
这里的sender指的是button。fromRect传的是button的尺寸,后面的inview传的是button本身。道理同上。
3.新建一个controller继承UITableViewController
4.编写数据源方法
#pragma mark - 数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{ return 20;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"第%d行数据",indexPath.row];
CGFloat red = arc4random_uniform(255) / 255.0;
CGFloat green = arc4random_uniform(255) / 255.0;
CGFloat black = arc4random_uniform(255) / 255.0;
cell.contentView.backgroundColor = [UIColor colorWithRed:red green:green blue:black alpha:1]; return cell;
}
5.效果图
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWlucWlhbmdxaWFuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
最新文章
- spring定时器
- 3、eclipse和maven环境安装以及HDFS读写的demo
- @interface NSFileManager : NSObject
- 什么是领域驱动设计(Domain Driven Design)?
- 菜鸟调错(七)——控制台中执行mvn命令后提示‘cmd’不是内部或外部命令
- [Neural Networks] Momentum
- Android 安卓实现页面相互跳转并相互传递参数
- [转]linux中颜色的含义
- hdu2222 ac自动机入门
- WPF学习之路一
- angr进阶(3) 添加约束
- Linux记录-jstack采集namenode堆栈信息
- python练习题-day9
- Python 函数(可变参数)
- Python(27)--文件相关处理的应用(增、删、改、查)
- SSM项目POST中文乱码解决方案
- Linux下的XAMPP基本配置技巧(设置虚拟主机、添加FTP账户等)
- Vue 框架-12-Vue 项目的详细开发流程
- eclipse Android 开发基础 Activity 窗体 界面
- CentOS7运维管理笔记(12)----修改主机名
热门文章
- Problem I: 零起点学算法88——青年歌手大奖赛_评委会打分
- 详解React的生命周期
- 转:Oracle密码过期,取消密码180天限制
- JS/JQuery判断是否移动设备+JS/JQuery判断浏览器类型
- jquery的表单验证方法,一个function能不能同时捕捉点击事件和按键事件?能不能再优化下,有代码。
- $(";#XXX";).click()和$(";#YYY";).on(";click";,";指定的元素";,function(){});的区别(jQuery动态绑定事件)
- 基于Python的交互式访问
- vc2005(visual studio)使用习惯记录
- if __name__=='__main__";在有的virtualenvs环境下执行成功,在有的环境下执行失败?
- 【云计算】Docker build解决父镜像层级关系过多问题:Cannot create container with more than 127 parents