練習(xí)

//

//? Model.h

//? 模擬

//

//? Created by 與你共度 on 2018/12/29.

//? Copyright ? 2018 與你共度. All rights reserved.

//

#import

NS_ASSUME_NONNULL_BEGIN

@interface Model : NSObject

@property(nonatomic,strong)NSString *photo;

@property(nonatomic,strong)NSString *title;

@property(nonatomic,strong)NSString *suitIntro;

@property(nonatomic,strong)NSString *readNum;

@end

NS_ASSUME_NONNULL_END






//

//? MyTableViewCell.h

//? 模擬

//

//? Created by 與你共度 on 2018/12/29.

//? Copyright ? 2018 與你共度. All rights reserved.

//

#import

@class Model;

@interfaceMyTableViewCell :UITableViewCell

@property(nonatomic ,strong)Model *m;

@end






//

//? MyTableViewCell.m

//? 模擬

//

//? Created by 與你共度 on 2018/12/29.

//? Copyright ? 2018 與你共度. All rights reserved.

//

#import "MyTableViewCell.h"

#import "Model.h"

#import "UIImageView+WebCache.h"

@interface MyTableViewCell ()

@property(nonatomic,strong)UIImageView *imgV;

@property(nonatomic,strong)UILabel *zhuTitle;

@property(nonatomic,strong)UILabel *fuTitle;

@property(nonatomic,strong)UILabel *readTitle;

@end

@implementationMyTableViewCell

//添加子控件

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier{

? ? if(self= [superinitWithStyle:stylereuseIdentifier:reuseIdentifier]) {

? ? ? ? [selfaddSubview:self.imgV];

? ? ? ? [selfaddSubview:self.zhuTitle];

? ? ? ? [selfaddSubview:self.fuTitle];

? ? ? ? [selfaddSubview:self.readTitle];

? ? }


? ? return self;

}

//懶加載

-(UIImageView *)imgV{

? ? if(!_imgV) {

? ? ? ? _imgV= [[UIImageViewalloc]init];


? ? }

? ? return _imgV;

}

-(UILabel*)zhuTitle{

? ? if(!_zhuTitle) {

? ? ? ? _zhuTitle= [[UILabelalloc]init];



? ? }

? ? return _zhuTitle;

}

-(UILabel*)fuTitle{

? ? if(!_fuTitle) {

? ? ? ? _fuTitle= [[UILabelalloc]init];

? ? }


? ? return _fuTitle;

}

-(UILabel*)readTitle{

? ? if (!_readTitle) {


? ? ? ? _readTitle= [[UILabelalloc]init];

? ? }


? ? return _readTitle;

}

//布局控件

-(void)layoutSubviews{


? ? [super layoutSubviews];


? ? self.imgV.frame=CGRectMake(5,5,100,100);

? ? self.zhuTitle.frame=CGRectMake(110,20,40,30);

? ? self.fuTitle.frame=CGRectMake(110,70,60,30);

? ? self.readTitle.frame = CGRectMake(300,100,20,20);

}

- (void)awakeFromNib {

? ? [superawakeFromNib];



? ? // Initialization code

}

-(void)setM:(Model *)m{

? ? _m = m;

? ? [self.imgV sd_setImageWithURL:[NSURL URLWithString:m.photo]];

? ? self.zhuTitle.text = m.title;

? ? self.fuTitle.text = m.suitIntro;

? ? self.readTitle.text = m.readNum;



}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

? ? [supersetSelected:selected animated:animated];

? ? // Configure the view for the selected state

}

@end



//

//? AppDelegate.h

//? 模擬

//

//? Created by 與你共度 on 2018/12/29.

//? Copyright ? 2018 與你共度. All rights reserved.

//

#import

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end






//

//? ViewController.m

//? 模擬

//

//? Created by 與你共度 on 2018/12/29.

//? Copyright ? 2018 與你共度. All rights reserved.

//

#import "ViewController.h"

#import "AFNetworking/AFNetworking.h"

#import "MJExtension/MJExtension.h"

#import "Model/Model.h"

#import "View/MyTableViewCell.h"

#define quanjuPath @"http://124.65.238.30:3300/bingyun/api/"

#define path @"strategy/page"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tab;

@property(nonatomic,strong)NSMutableArray *dataSouace;

@end

@implementation ViewController

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

? ? return self.dataSouace.count;

}

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

? ? MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

? ? if(!cell) {

? ? ? ? cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];

? ? }

? ? //創(chuàng)建模型

? ? Model*m =self.dataSouace[indexPath.row];

? ? cell.m= m;


? ? returncell;


}

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

? ? return 150;

}

- (void)viewDidLoad {

? ? [super viewDidLoad];


? ? self.dataSouace = [NSMutableArray array];


? ? self.tab = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];

? ? self.tab.delegate=self;

? ? self.tab.dataSource = self;

? ? [self.viewaddSubview:self.tab];


? ? //創(chuàng)建網(wǎng)絡(luò)請(qǐng)求管理者

? ? AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

? ? //拼接url

? ? NSString*str = [NSStringstringWithFormat:@"%@%@",quanjuPath,path];


? ? //將參數(shù)包裝成字典

? ? NSDictionary *dic = @{

? ? ? ? ? ? ? ? ? ? ? ? ? @"pageSize":@"10",

? ? ? ? ? ? ? ? ? ? ? ? ? @"strategyType":@"POSTURE",

? ? ? ? ? ? ? ? ? ? ? ? ? @"pageNo":@"1"

? ? ? ? ? ? ? ? ? ? ? ? ? };



? ? [managerGET:strparameters:dicsuccess:^(NSURLSessionDataTask*task,idresponseObject) {


? ? ? ? //處理服務(wù)器數(shù)據(jù)

? ? ? ? NSArray*arr = responseObject[@"data"];

? ? ? ? for(NSDictionary*dicinarr) {


? ? ? ? ? ? //字典轉(zhuǎn)模型

? ? ? ? ? ? Model*m = [Modelmj_objectWithKeyValues:dic];


? ? ? ? ? ? [self.dataSouaceaddObject:m];

? ? ? ? }


? ? ? ? //刷新表格

? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? [self.tabreloadData];

? ? ? ? });


? ? }failure:^(NSURLSessionDataTask *task, NSError *error) {


? ? }];


? ? // Do any additional setup after loading the view, typically from a nib.

}

@end

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容