WXHL 学习总结(七)

               通过一个多月的学习,UI基础已经讲完,能做出一些简单的小案例,从这周开始,就着手开始真正的第一个小项目了。还是有一定的收获的
下面是一些简单的表视图的应用案例:

1 微博 :练习使用自定义单元格,主要是计算好每个单元格的高度,以及单元格内每个控件的frame,因为有些是会员,有的有插图,有的没插图,所以计算略显复杂

#pragma mark - 复写get方法

-(NSArray *)weibos{


    if (_weibos == nil) {

        //获取plist文件路径

        NSString *path = [[NSBundle mainBundlepathForResource:@"statuses.plist" ofType:nil];

        //将数据放进数组

        self.weibos = [NSArray arrayWithContentsOfFile:path];

        //定义一个可变数组  存放模型

        NSMutableArray *models = [NSMutableArray array];

        //字典转模型

        for (NSDictionary *dict in self.weibos) {

            WXWeibo *model = [WXWeibo weiboWithDict:dict];

            [models addObject:model];

            

        }

        

        _weibos = models;

    }


    return _weibos;

}



- (void)viewDidLoad {

    [super viewDidLoad];

    

    self.tableView.frame = CGRectMake(064375603);


}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


#pragma mark - Table view 数据源方法


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {


    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


    return self.weibos.count;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    

    // 1 获取模型对象

    WXWeibo *weibo = self.weibos[indexPath.row];

    

    // 2 创建单元格

    static NSString *identifier = @"weibo_cell";


    WXWeiboCell *cell = [[WXWeiboCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

    

    // 3 给单元格赋值

        cell.weibo = weibo;

    

    // 4 返回单元格

    return cell;

}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    

    WXWeibo *weibo = self.weibos[indexPath.row];

    

    NSString *text = weibo.text;

    

    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:16constrainedToSize:CGSizeMake(3501000)];

    

    

    //如果有图片  加上图片的高度

    if (weibo.picture) {

        return size.height + 40 + 35 + 100;

    }else{

        //没有图片  返回正文高度 头像高度  之和

        return size.height + 30 +35;

    }


}


效果图: 图片






2.  汽车列表、LOL英雄列表   :  练习单元格的使用,以及重用问题
汽车展示:分组展示每个系列的车   右侧通过方法添加索引
英雄展示:可以点击单元格,修改英雄的名字

效果图:
图片

图片


图片

图片

 
图片图片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值