zoukankan      html  css  js  c++  java
  • ios开发之--UITableView中的visibleCells的用法

    先上图:

    具体代码如下:

    #import "ViewController.h"
    
    @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
    @property(nonatomic,strong)UITableView *myTableV;
    @property(nonatomic,strong)NSArray *contentAry;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        self.contentAry = [NSArray array];
        [self creatUI];
    }
    - (IBAction)leftAction:(id)sender {
        self.contentAry = self.myTableV.visibleCells;
        NSLog(@"----%@",self.contentAry);
        
        UIButton *button = (UIButton*)sender;
        button.selected = !button.selected;
        CGAffineTransform transform;
        double duration = 0.1;
        
        if (button.tag == 1) {
            transform = CGAffineTransformMakeTranslation(-[UIScreen mainScreen].bounds.size.width, 0);
        }else if (button.tag == 2)
        {
            for (UITableViewCell *cell in self.contentAry) {
                [UIView animateWithDuration:duration delay:0 options:0 animations:^{
                    cell.transform = CGAffineTransformIdentity;
                } completion:^(BOOL finished) {
                    
                }];
                duration += 0.1;
            }
            return;
        }else
        {
            transform = CGAffineTransformMakeTranslation([UIScreen mainScreen].bounds.size.width, 0);
        }
        
        for (UITableViewCell *cell in self.contentAry) {
            [UIView animateWithDuration:duration delay:0 options:0 animations:^{
                cell.transform = transform;
            } completion:^(BOOL finished) {
                
            }];
            duration += 0.1;
        }
        
    }
    
    -(void)creatUI
    {
        self.myTableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 100) style:UITableViewStylePlain];
        self.myTableV.delegate = self;
        self.myTableV.dataSource = self;
        self.myTableV.tableFooterView = [[UIView alloc]init];
        [self.view addSubview:self.myTableV];
    }
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 5;
    }
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *celliden = @"CELLS";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celliden];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:celliden];
        }
        cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
        cell.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.6];
        return cell;
    }

    仅做记录!

  • 相关阅读:
    HDU 5451 Best Solver(fibonacci)
    BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)
    HDU
    Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness (三分)
    Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B "Or" Game (贪心)
    Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline(数学)
    ZOJ 1729 Hidden Password (字符串最小表示)
    UVA 11627 Slalom(二分)
    UVALive 4254 Processor(二分)
    UVA 10905 Children's Game (贪心)
  • 原文地址:https://www.cnblogs.com/hero11223/p/8137194.html
Copyright © 2011-2022 走看看