#import<UIKit/UIKit.h>#import "t20140628025200nsnumber+message.h"#import "t20140628025200nsstring+urlencoding.h"#import "MKNetworkEngine.h"#import "MKNetworkOperation.h"@interfaceT20140628025200viewcontroller:uitableviewcontroller@property (nonatomic,strong) NSMutableArray*ListData;//receives data returned from the server. @property (strong,nonatomic) Nsmutabledata *datas;//Query All-(void) FindAll;@end
#import "T20140628025200ViewController.h"@interfaceT20140628025200viewcontroller ()@end@implementationT20140628025200viewcontroller- (void) viewdidload{[Super Viewdidload]; //1. Initialize Data[self findAll];}- (void) didreceivememorywarning{[Super didreceivememorywarning];}#pragmaMark Table datasource-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{returnSelf.listData.count;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//1. Initialize cell reuse StaticNSString *reusecell =@"Reusecell"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:reusecell]; if(Cell = =Nil) {Cell=[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:reusecell]; } //2. Configuration Reuse Cell Datansmutabledictionary* dict =Self.listdata[indexpath.row]; Cell.textLabel.text= [Dict Objectforkey:@"Content"]; Cell.detailTextLabel.text= [Dict Objectforkey:@"CDate"]; returncell;}-(void) findall{NSString*path = [[NSString alloc] Initwithformat:@"/kujizu/test01.html"]; Mknetworkengine*engine = [[Mknetworkengine alloc] Initwithhostname:@"127.0.0.1:8080"Customheaderfields:nil]; Mknetworkoperation*op =[engine Operationwithpath:path]; [Op addcompletionhandler:^ (Mknetworkoperation *operation) {NSLog (@"responsedata:%@", [Operation Responsestring]); NSData*data =[Operation ResponseData]; Nsdictionary*resdict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments Error:nil]; if(Data = =Nil) {Self.listdata=[[Nsmutablearray alloc] init]; Uialertview*alertview = [[Uialertview alloc] Initwithtitle:@"error Message"Message@"no data. " Delegate: Nil Cancelbuttontitle:@"OK"Otherbuttontitles:nil]; [Alertview show]; }Else{NSNumber*resultcodeobj = [Resdict objectforkey:@"ResultCode"]; if([Resultcodeobj IntegerValue] >=0) {Self.listdata= [Resdict Objectforkey:@"Record"]; [Self.tableview Reloaddata]; } Else{nsstring*errorstr =[Resultcodeobj errormessage]; Uialertview*alertview = [[Uialertview alloc] Initwithtitle:@"error Message"Message:errorstrDelegate: Nil Cancelbuttontitle:@"OK"Otherbuttontitles:nil]; [Alertview show]; }}} ErrorHandler:^ (Mknetworkoperation *errorop, nserror*err) {NSLog (@"mknetwork Request Error:%@", [err localizeddescription]); }]; [Engine enqueueoperation:op];}@end