前言
这个月的任务是完成知乎日报,难度还是挺高的 要完成的部分有:首页各个内容,我的界面,我的收藏和消息中心
在这个周基本上完成了各个界面和首页轮播图和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];
总结
这周写的内容比较少,一直卡在那个请求到的数据为空的问题上。下周赶进度。
|