ios开发之--UITableView中的visibleCells的用法

时间:2023-01-28 13:24:26

先上图:

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 == ) {
transform = CGAffineTransformMakeTranslation(-[UIScreen mainScreen].bounds.size.width, );
}else if (button.tag == )
{
for (UITableViewCell *cell in self.contentAry) {
[UIView animateWithDuration:duration delay: options: animations:^{
cell.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) { }];
duration += 0.1;
}
return;
}else
{
transform = CGAffineTransformMakeTranslation([UIScreen mainScreen].bounds.size.width, );
} for (UITableViewCell *cell in self.contentAry) {
[UIView animateWithDuration:duration delay: options: animations:^{
cell.transform = transform;
} completion:^(BOOL finished) { }];
duration += 0.1;
} } -(void)creatUI
{
self.myTableV = [[UITableView alloc]initWithFrame:CGRectMake(, , self.view.bounds.size.width, self.view.bounds.size.height - ) 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 ;
} -(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;
}

仅做记录!