IOS开发基础之微博项目

本文主要介绍如何进行iOS开发,以实现一个基础的微博项目。内容涵盖关键性的代码实现。
摘要由CSDN通过智能技术生成

IOS开发基础之微博项目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

关键性代码

//
//  NJViewController.m
//  06-预习-微博(通过代码自定义cell)

//
#import "NJViewController.h"
#import "NJWeiboCell.h"
#import "NJWeibo.h"
#import "NJWeiboFrame.h"

@interface NJViewController ()
@property (nonatomic, strong) NSMutableArray *weiboFrames;
@end

@implementation NJViewController

- (NSMutableArray *)weiboFrames
{
   
    if (_weiboFrames == nil) {
   
        // 1.加载数据
        NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"weibo.plist" ofType:nil]];
        
        // 2.字典 转成 模型
        _weiboFrames = [NSMutableArray array];
        for (NSDictionary *dict in array) {
   
            // 创建frame对象
            NJWeiboFrame *weiboF = [[NJWeiboFrame alloc] init];
            weiboF.weibo = [NJWeibo weiboWithDict:dict];
            
            [_weiboFrames addObject:weiboF];
        }
    }
    return _weiboFrames;
}

- (BOOL)prefersStatusBarHidden
{
   
    return YES;
}

#pragma mark - 数据源方法
#pragma mark 一共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   
    return self.weiboFrames.count;
}

#pragma mark 每一行显示怎样的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    // 1.去缓存池中取出cell
    static NSString *ID = @"weibo";
    NJWeiboCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    // 2.缓存池没有cell,重新创建cell
    if (cell == nil) {
   
        cell = [[NJWeiboCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    
    // 3.传递模型数据
    cell.weiboFrame = self.weiboFrames[indexPath.row];
    
    return cell;
}

#pragma mark - 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    return [self
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值