Skip to content

Commit

Permalink
加载news全部数据
Browse files Browse the repository at this point in the history
  • Loading branch information
liubo authored and liubo committed Aug 20, 2017
1 parent 6249b23 commit d7f06c7
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 16 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added LBNewsComing/.DS_Store
Binary file not shown.
20 changes: 17 additions & 3 deletions LBNewsComing/LBNewsComing.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
3AD9FCB41F4933C1002EB75B /* LBNCImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AD9FCB31F4933C1002EB75B /* LBNCImageView.m */; };
6A7239FDE3F8DB72CFF7D452 /* libPods-LBNewsComing.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 85324EFC2A18ED7C5CFD4374 /* libPods-LBNewsComing.a */; };
F8759C0C1F468635009DADF7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F8759C0B1F468635009DADF7 /* main.m */; };
F8759C151F468635009DADF7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F8759C131F468635009DADF7 /* Main.storyboard */; };
Expand Down Expand Up @@ -51,6 +52,8 @@

/* Begin PBXFileReference section */
0B97BC6530F0AB897F6A3D05 /* Pods-LBNewsComing.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LBNewsComing.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LBNewsComing/Pods-LBNewsComing.debug.xcconfig"; sourceTree = "<group>"; };
3AD9FCB21F4933C1002EB75B /* LBNCImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LBNCImageView.h; sourceTree = "<group>"; };
3AD9FCB31F4933C1002EB75B /* LBNCImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LBNCImageView.m; sourceTree = "<group>"; };
85324EFC2A18ED7C5CFD4374 /* libPods-LBNewsComing.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LBNewsComing.a"; sourceTree = BUILT_PRODUCTS_DIR; };
F3B3903665C43C99966A8A10 /* Pods-LBNewsComing.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LBNewsComing.release.xcconfig"; path = "Pods/Target Support Files/Pods-LBNewsComing/Pods-LBNewsComing.release.xcconfig"; sourceTree = "<group>"; };
F8759C071F468635009DADF7 /* LBNewsComing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LBNewsComing.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -153,6 +156,15 @@
name = Frameworks;
sourceTree = "<group>";
};
3AD9FCB11F4933C1002EB75B /* LBNCImageView */ = {
isa = PBXGroup;
children = (
3AD9FCB21F4933C1002EB75B /* LBNCImageView.h */,
3AD9FCB31F4933C1002EB75B /* LBNCImageView.m */,
);
path = LBNCImageView;
sourceTree = "<group>";
};
A51440517346E17184A807E7 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -298,6 +310,7 @@
F8759C2F1F468988009DADF7 /* common */ = {
isa = PBXGroup;
children = (
3AD9FCB11F4933C1002EB75B /* LBNCImageView */,
F8F003F51F47EE0900DA43EA /* Additions */,
F8759C661F46CF56009DADF7 /* NSObject+Hint */,
);
Expand Down Expand Up @@ -547,7 +560,7 @@
TargetAttributes = {
F8759C061F468635009DADF7 = {
CreatedOnToolsVersion = 8.3.3;
DevelopmentTeam = MECQS3Z269;
DevelopmentTeam = 9266GAZZ3C;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -664,6 +677,7 @@
F8759C8D1F46E987009DADF7 /* LBNCVideoCell.m in Sources */,
F8759C6C1F46D216009DADF7 /* LBNCNewsNetManager.m in Sources */,
F8759C871F46E95A009DADF7 /* LBNCChartCell.m in Sources */,
3AD9FCB41F4933C1002EB75B /* LBNCImageView.m in Sources */,
F8759C721F46D476009DADF7 /* LBNCBaseModel.m in Sources */,
F8F0040F1F47EE0900DA43EA /* NSArray+Log.m in Sources */,
F8F004131F47EE0900DA43EA /* NSString+CZHash.m in Sources */,
Expand Down Expand Up @@ -793,7 +807,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = MECQS3Z269;
DEVELOPMENT_TEAM = 9266GAZZ3C;
GCC_PREFIX_HEADER = LBNewsComing/LBNCPrefixHeader.pch;
INFOPLIST_FILE = LBNewsComing/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
Expand All @@ -809,7 +823,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = MECQS3Z269;
DEVELOPMENT_TEAM = 9266GAZZ3C;
GCC_PREFIX_HEADER = LBNewsComing/LBNCPrefixHeader.pch;
INFOPLIST_FILE = LBNewsComing/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
Expand Down
Binary file added LBNewsComing/LBNewsComing/Classes/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// LBNCImageView.h
// LBNewsComing
//
// Created by liubo on 2017/8/20.
// Copyright © 2017年 刘博. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface LBNCImageView : UIView
//按比例放大、充满 当前视图减掉超出自身区域的图片部分
@property (strong, nonatomic) UIImageView *imageView;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// LBNCImageView.m
// LBNewsComing
//
// Created by liubo on 2017/8/20.
// Copyright © 2017年 刘博. All rights reserved.
//

#import "LBNCImageView.h"

@implementation LBNCImageView

- (UIImageView *)imageView{
if(_imageView == nil) {
_imageView = [[UIImageView alloc] init];
_imageView.contentMode = UIViewContentModeScaleAspectFill;
self.clipsToBounds = YES;
[self addSubview:_imageView];
[_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
}];
}
return _imageView;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ @implementation LBNCListController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
//[self.newsTableView.mj_header beginRefreshing];
[self newsTableView];
[self.newsTableView.mj_header beginRefreshing];
// [self newsTableView];
}
-(LBNCNewsViewModel *)newsViewModel{
if (_newsViewModel == nil) {
Expand All @@ -43,6 +43,7 @@ -(LBNCNewsTableView *)newsTableView{
[self.newsViewModel refreshDataCompletionHandler:^(NSError *error) {
if (!error) {
//_newsTableView.tableHeaderView = [self setUpTableHeaderView];
self.newsTableView.dataArray = self.newsViewModel.dataMArr;
}
//[_newsTableView.mj_header endRefreshing];
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

#import <UIKit/UIKit.h>

#import "LBNCNewsModel.h"
@interface LBNCNewsCell : UITableViewCell
+ (instancetype)cellWithTableView:(UITableView *)tableView;
// 新闻列表模型
@property (nonatomic, strong)HomeResultNewslistModel *newsListModel;
@end
79 changes: 72 additions & 7 deletions LBNewsComing/LBNewsComing/Classes/view/newsView/LBNCNewsCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
//

#import "LBNCNewsCell.h"

#import <UIImageView+WebCache.h>
@implementation LBNCNewsCell{



LBNCImageView *_iconIV;
UILabel *_titleLabel;
UILabel *_dateLabel;
UILabel *_commentNumLabel;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
Expand All @@ -29,10 +31,75 @@ -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStri
}
return self;
}
// 对此简单布局使用懒加载也可以,再在setModel中进行赋值
//- (LBNCImageView *)iconIV {
// if(_iconIV == nil) {
// _iconIV = [[LBNCImageView alloc] init];
// [self.contentView addSubview:_iconIV];
// [_iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.left.mas_equalTo(10);
// make.size.mas_equalTo(CGSizeMake(80, 60));
// make.centerY.mas_equalTo(0);
// }];
// }
// return _iconIV;
//}
- (void)autoLayout{


// 图片
_iconIV = [[LBNCImageView alloc] init];
[self.contentView addSubview:_iconIV];
[_iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.mas_equalTo(10);
make.size.mas_equalTo(CGSizeMake(80, 60));
make.centerY.mas_equalTo(0);
}];
// 标题
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = kTitleFont;
_titleLabel.numberOfLines = 0;
[self.contentView addSubview:_titleLabel];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(_iconIV.mas_right).mas_equalTo(10);
make.right.mas_equalTo(-10);
make.topMargin.mas_equalTo(_iconIV);
}];
// 日期
_dateLabel = [[UILabel alloc] init];
_dateLabel.font = kSubtitleFont;
_dateLabel.textColor = [UIColor lightGrayColor];
[self.contentView addSubview:_dateLabel];
[_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leftMargin.mas_equalTo(_titleLabel);
make.width.mas_equalTo(80);
make.bottomMargin.mas_equalTo(_iconIV);
}];
// 评论
_commentNumLabel = [[UILabel alloc] init];
_commentNumLabel.font = kSubtitleFont;
_commentNumLabel.textColor = [UIColor lightGrayColor];
_commentNumLabel.textAlignment = NSTextAlignmentRight;
[self.contentView addSubview:_commentNumLabel];
[_commentNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(_dateLabel);
make.right.mas_equalTo(-10);
make.width.mas_equalTo(80);
}];
}
-(void)setNewsListModel:(HomeResultNewslistModel *)newsListModel{
_newsListModel = newsListModel;
if (newsListModel.mediatype == 6) {
_iconIV.imageView.image = [UIImage imageNamed:@"car"];
}else{
[_iconIV.imageView sd_setImageWithURL:[NSURL URLWithString:newsListModel.smallpic] placeholderImage:[UIImage imageNamed:@"cell_bg_noData_1"]];
}
if (newsListModel.mediatype == 3) {
_commentNumLabel.text = [NSString stringWithFormat:@"%ld播放",newsListModel.replycount];
}else{
_commentNumLabel.text = [NSString stringWithFormat:@"%ld评论",newsListModel.replycount];
}
_titleLabel.text = newsListModel.title;
_dateLabel.text = newsListModel.time;
}
- (instancetype)init
{
self = [super init];
Expand All @@ -44,6 +111,4 @@ - (instancetype)init
-(void)layoutSubviews{
[super layoutSubviews];
}


@end
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ - (void)setDataArray:(NSMutableArray *)dataArray{
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _dataArray.count;
}
// 估计cell高度
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
LBNCNewsCell *cell = [LBNCNewsCell cellWithTableView:tableView];

cell.newsListModel = self.dataArray[indexPath.row];
return cell;

}
Expand Down
28 changes: 27 additions & 1 deletion LBNewsComing/LBNewsComing/LBNCHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,34 @@
#ifdef DEBUG
///LBNCLog是不限制参数的,中间用三个英文句号表示
#define LBNCLog(...) NSLog(__VA_ARGS__)
#define kHeight [UIScreen cz_screenHeight] / 750.0
///如果是发布状态LBNCLog就直接为空
#define kHeight [UIScreen cz_screenHeight] / 750.0
//标题字体
#define kTitleFont [UIFont systemFontOfSize:15]
//子标题字体
#define kSubtitleFont [UIFont systemFontOfSize:13]
//通过RGB设置颜色
#define kRGBColor(R,G,B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0]
//应用程序的屏幕高度
#define kWindowH [UIScreen mainScreen].bounds.size.height
//应用程序的屏幕宽度
#define kWindowW [UIScreen mainScreen].bounds.size.width

//通过Storyboard ID 在对应Storyboard中获取场景对象 (\:换行)
#define kVCFromSb(storyboardId, storyboardName) [[UIStoryboard storyboardWithName:storyboardName bundle:nil] \
instantiateViewControllerWithIdentifier:storyboardId]

//移除iOS7之后,cell默认左侧的分割线边距 Preserve:保存
#define kRemoveCellSeparator \
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{\
cell.separatorInset = UIEdgeInsetsZero;\
cell.layoutMargins = UIEdgeInsetsZero; \
cell.preservesSuperviewLayoutMargins = NO; \
}

//Docment文件夹目录
#define kDocumentPath NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject

#elif
#define LBNCLog(...)
#endif
4 changes: 4 additions & 0 deletions LBNewsComing/LBNewsComing/LBNCPrefixHeader.pch
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// 类似网易新闻首页,控制器滑动翻页效果的控制器
#import "WMPageController.h"
#import "AFNetworking.h"
// 类型toast提示框
#import "NSObject+Hint.h"
// 实现安卓toast风格提示,弹出提示框架
#import "MBProgressHUD.h"
Expand All @@ -21,7 +22,10 @@
#import "MJRefresh.h"
//#import "SDWebImage/uiim"
#import "Masonry.h"
// 轮播图
#import "SDCycleScrollView.h"
#import "CZAdditions.h"
// 宏定义引入
#import "LBNCHeader.h"
//按比例放大、充满 当前视图减掉超出自身区域的图片部分
#import "LBNCImageView.h"
22 changes: 21 additions & 1 deletion notes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ SDCycleScrollView
4.
网络封装
枚举类型
MVVM模式
MVVM模式
(1)viewModel里面处理的是加载网络数据,把模型数组传过去
(2)model里面
/** 属性为数组 对应相应的解析类 */
+ (NSDictionary *)objectClassInArray{
return @{@"newslist" : [HomeResultNewslistModel class], @"focusimg" : [HomeResultFocusimgModel class]};
}
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
return @{@"ID":@"id"};
}
/** 属性为字典 对应相应的解析类 */

5.
注意block delegate 一块使用
LBNCBaseViewModel
为自己设置代理但是没有代理属性
[self.dataMArr addObjectsFromArray:model.result.newslist];
// 估计cell高度
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}

0 comments on commit d7f06c7

Please sign in to comment.