iOS开发的UI制作中动态和静态单元格的基本使用教程

2020-01-14 17:39:10王冬梅

#pragma mark- 设置tableview的数据源方法
//组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
//行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.apps.count;
}
//组-行-数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //创建cell
    static NSString *identifier=@"app";
    YYappCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    //设置cell的数据
    YYappInfo *appinfo=self.apps[indexPath.row];
    //设置代理
    cell.delegate=self;
    cell.app=appinfo;
    //返回cell
    return cell;
}

#pragma mark- 设置代理
-(void)btnDidClick:(YYappCell *)cell
{
    //取出模型
    YYappInfo *app=cell.app;
    NSLog(@"daili");
    UILabel *lab=[[UILabel alloc]init];
    //提示的显示位置
    lab.frame=CGRectMake(60, 300, 200, 20);
    //设置提示文本
    lab.text=[NSString stringWithFormat:@"%@已经下载完成",app.name];
    //设置文本背景颜色
    [lab setBackgroundColor:[UIColor grayColor]];
    [self.view addSubview:lab];
    lab.alpha=1.0;
    
    //设置动画效果
    [UIView animateWithDuration:2.0 animations:^{
        lab.alpha=0.0;
    } completion:^(BOOL finished) {
        //把弹出的提示信息从父视图中删除
        [lab removeFromSuperview];
    }];
}

#pragma mark-隐藏状态栏
-(BOOL)prefersStatusBarHidden
{
    return YES;
}

@end


补充说明

 

  在程序中通过标示符取出对应的cell,是因为在storyboard中已经对cell打上了标示符(app)的标签。

复制代码
//组-行-数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath