#import <UIKit/UIKit.h>#import"t20140628025702nsnumber+message.h" #import"t20140628025702nsstring+urlencoding.h"@interface *listData; // Query All -(void) findAll; @end
#import "T20140628025702ViewController.h"@interfaceT20140628025702viewcontroller ()@end@implementationT20140628025702viewcontroller- (void) viewdidload{[Super Viewdidload]; //1. Initialize Data[self findAll]; //Initialize UirefreshcontrolUirefreshcontrol *RC =[[Uirefreshcontrol alloc] init]; Rc.attributedtitle= [[Nsattributedstring alloc]initwithstring:@"Drop- down refresh"]; [RC addtarget:self Action: @selector (Refreshtableview) forcontrolevents:uicontroleventvaluechanged]; Self.refreshcontrol=RC;}-(void) refreshtableview{if(self.refreshControl.refreshing) {Self.refreshControl.attributedTitle= [[Nsattributedstring alloc]initwithstring:@"Loading in ..."]; [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*strurl = [[NSString alloc] Initwithformat:@"http://127.0.0.1:8080/kujizu/test01.html"]; Nsurl*url =[Nsurl Urlwithstring:[strurl urlencodedstring]; Nsurlrequest*request =[[Nsurlrequest alloc] initwithurl:url]; NSData*data =[nsurlconnection sendsynchronousrequest:request returningresponse:nil 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{nsdictionary*resdict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments Error:nil]; NSNumber*resultcodeobj = [Resdict objectforkey:@"ResultCode"]; if([Resultcodeobj IntegerValue] >=0) {Self.listdata= [Resdict Objectforkey:@"Record"]; } Else{nsstring*errorstr =[Resultcodeobj errormessage]; Uialertview*alertview = [[Uialertview alloc] Initwithtitle:@"error Message"Message:errorstrDelegate: Nil Cancelbuttontitle:@"OK"Otherbuttontitles:nil]; [Alertview show]; } } if(Self.refreshcontrol) {[Self.refreshcontrol endrefreshing]; Self.refreshControl.attributedTitle= [[Nsattributedstring alloc]initwithstring:@"Drop- down refresh"]; }}@end