Add some third-party class libraries afnetworking, Jsonkit-nowarning, Ocmapper, Sdwebimage
#import "AFNetworking.h"
#import "JSONKit.h"
#import "FirstModel.h"
#import "Nsobject+objectmapper.h"
#import "SDImageCache.h"
#import "Uiimageview+webcache.h"
@interface Viewcontroller () <UITableViewDataSource,UITableViewDelegate>
{
Nsarray *_hotarray;
}
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
UITableView *tableview =[[uitableview alloc]initwithframe:cgrectmake (0, Self.view.frame.size.width, self.view.frame.size.height) Style:uitableviewstyleplain];
Tableview.delegate =self;
Tableview.datasource =self;
[Self.view Addsubview:tableview];
Tableview.tablefooterview=[uiview new];
NSString *urlstr [email protected] "http://www.022eh.com/api/return_sub";
Nsdictionary *dic [Email protected]{@ "PageSize": @ "3" @ "index": @ "1"};
Afhttprequestoperationmanager *manager =[afhttprequestoperationmanager Manager];
[Manager post:urlstr Parameters:dic success:^ (afhttprequestoperation *operation, id responseobject) {
NSLog (@ "0000000=%@", operation.responsestring);
Nsdictionary *resat =[operation.responsedata Objectfromjsondata];
Nsdictionary *data =[resat objectforkey:@ "List"];
_hotarray =[firstmodel Objectfromdictionary:data];
[TableView Reloaddata];
} failure:^ (Afhttprequestoperation *operation, Nserror *error) {
}];
}
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{
return _hotarray.count;
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
UITableViewCell *cell =[tableview dequeuereusablecellwithidentifier:@ "Cell"];
if (!cell) {
Cell =[[uitableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:@ "Cell"];
}
Firstmodel *first =[_hotarray ObjectAtIndex:indexPath.row];
Cell.textlabel.text=first.name;
[Cell.imageview sd_setimagewithurl:[nsurl urlwithstring:[nsstring stringwithformat:@ "http://www.022eh.com%@", FIRST.IMG]] placeholderimage:[uiimage imagenamed:@ "908fa0ec08fa513df6da05f9386d55fbb2fbd9a1.jpg"];
return cell;
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
}
@end
Add in Firstmodel.h
#import <Foundation/Foundation.h>
@interface Firstmodel:nsobject
@property (Nonatomic,strong) nsstring *name;//to match the given number of letters
@property (nonatomic) NSString *id;
@property (Nonatomic,strong) NSString *img;
@end
Map request data to model class