zoukankan      html  css  js  c++  java
  • 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.效果图



  • 相关阅读:
    mybatis 缓存
    mybatis 级联
    mybatis 传递多个参数
    mybatis 枚举typeHandler
    mybatis 自定义typeHandler
    mybatis typeHandler类型转换器
    Fastjson 序列化与反序列化
    单独使用MyBatis的简单示例
    dubbo+zookeeper+springboot简单示例
    intellij 插件的使用
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/7264973.html
Copyright © 2011-2022 走看看