知乎日报总结——第一周


前言

这个月的任务是完成知乎日报,难度还是挺高的 要完成的部分有:首页各个内容,我的界面,我的收藏和消息中心

在这个周基本上完成了各个界面和首页轮播图和cell的添加


效果

首页:
在这里插入图片描述
我的:
在这里插入图片描述

遇到的问题

1.UIButton的添加出现一些奇怪的事

详情请戳:UIButton的类型

2.关于网络请求一直为空

我在controller里的网络请求成功了,但是在view里使用的时候,总是为空。
咨询了大佬后,大佬指出是因为先加载了view,然后在对controller进行的赋值。

我是使用的属性传值,把网络请求到的数据转换成字典类型,然后在controller里属性传值到view里面
这个是解决先创建view在网络请求导致的数据为空问题代码。


    [[Manager shareManger]makeData:^(HomeModel * _Nonnull ViewModel) {
        NSLog(@"%@", ViewModel.top_stories[4]);
        NSLog(@"%@", ViewModel.stories[4]);
        self.viewHome.homeDictionary = [ViewModel toDictionary];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.viewHome CreatView];
        });
    } error:^(NSError * _Nonnull error) {
        NSLog(@"请求失败!");
    }];
    [self.view addSubview:self.viewHome];

3.轮播图

轮播图就不多说了,之前写过很多次了。
写的时候注意滑动时候的bug解决了就行。

4.图片的添加

由于这次使用的是网络上的图片,添加方法有些许不一样
这里是轮播图上的图片添加


        NSString* homeScrollImageName = self.homeDictionary[@"top_stories"][i][@"image"];
        NSURL *imageUrl = [NSURL URLWithString:homeScrollImageName];
        UIImage *homeScrollImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageUrl]];
        UIImageView* homeScrollImageView = [[UIImageView alloc] initWithImage:homeScrollImage];
        homeScrollImageView.frame = CGRectMake(WIDTH*i, 0, WIDTH, 400);
        [self.scrollView addSubview:homeScrollImageView];

5.首页左上角时间

要获取当前时间进行添加
由于直接获取得到的格式和所需格式不一样,必须重新想出一个方法来添加首页时间
我的方法比较笨, 是先获取时间,然后进行格式转换

NSDate *dateOne = [NSDate date];
    NSDateFormatter *forMatter = [[NSDateFormatter alloc] init];
    [forMatter setDateFormat:@"dd"];
    NSString *dateStr = [forMatter stringFromDate:dateOne];
    
    
    UILabel* labDateOne = [[UILabel alloc] init];
    labDateOne.frame = CGRectMake(20, 20, 60, 40);
    labDateOne.text = dateStr;
    [labDateOne setFont:[UIFont fontWithName:@"Helvetica-Bold" size:35]];
    [self addSubview:labDateOne];
    
    
    
    NSDate *date =[NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
     
    [formatter setDateFormat:@"MM"];
    NSInteger currentMonth=[[formatter stringFromDate:date]integerValue];
    
    UILabel* labDateTwo = [[UILabel alloc] init];
    labDateTwo.frame = CGRectMake(20, 50, 60, 40);
    labDateTwo.font = [UIFont systemFontOfSize:20];
    
    if (currentMonth == 10){
        NSString* Month = @"十月";
        labDateTwo.text = Month;
        
    } else if (currentMonth == 9){
        NSString* Month = @"九月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 8){
        NSString* Month = @"八月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 7){
        NSString* Month = @"七月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 6){
        NSString* Month = @"六月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 5){
        NSString* Month = @"五月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 4){
        NSString* Month = @"四月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 3){
        NSString* Month = @"三月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 2){
        NSString* Month = @"二月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 1){
        NSString* Month = @"一月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 11){
        NSString* Month = @"十一月";
        labDateTwo.text = Month;
        
    }else if (currentMonth == 12){
        NSString* Month = @"十二月";
        labDateTwo.text = Month;
        
    }
    
    [self addSubview:labDateTwo];

总结

这周写的内容比较少,一直卡在那个请求到的数据为空的问题上。下周赶进度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山河丘壑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值