2012-03-04 74 views
0

我還有一個問題,這個時候,我取將被用來填充的tableview我在我的廈門國際銀行這樣的JSON代碼,開始與我的.h文件中流JSON來實現代碼如下

@interface FirstViewController : UIViewController<UITableViewDelegate, UITableViewDataSource, ASIHTTPRequestDelegate> { 
NSMutableArray *resultArray; 
IBOutlet UITableView *thetableView; 
NSMutableData *responseData; 

}

@property (nonatomic,retain) NSArray *arrayTypes; 
@property (nonatomic,retain) NSMutableArray *resultArray; 
@property (nonatomic,retain) IBOutlet UITableView *thetableView; 
在我的.m文件

我在connectiondidfinishloading實現了這個

- (void) viewDidLoad{ 
responseData = [[NSMutableData data]retain]; 
NSURL *url = [NSURL URLWithString:@"http://localhost/fetch.php"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[[NSURLConnection alloc] initWithRequest:request delegate:self];  
[super viewDidLoad]; 
[self.thetableView reloadData]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
[connection release]; 

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
[responseData release]; 
NSLog(@"%@", responseString); 
NSDictionary *dictionary = [responseString JSONValue]; 
NSMutableArray *response = [dictionary valueForKey:@"itemn"]; 
resultArray = [[NSArray alloc] initWithArray:response]; 

}

現在的問題,實現代碼如下實施了兩個numberofrowsinsection和didselectrowatindextpath方法,但後者從來沒有所謂的數組的大小爲0,甚至重裝,它不工作時我錯過了什麼或者是否有類似的教程要遵循?遺憾的長度只是希望將相關信息將是有益的

回答

0

你應該重新加載tableview中,一旦你有完整的data..see更新的代碼

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
[connection release]; 

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
[responseData release]; 
NSLog(@"%@", responseString); 
NSDictionary *dictionary = [responseString JSONValue]; 
NSMutableArray *response = [dictionary valueForKey:@"itemn"]; 
resultArray = [[NSArray alloc] initWithArray:response]; 

//Reload your table with data.. 
[self.thetableView reloadData]; 
} 
+0

OMG!有效!傻我應該嘗試過,並嘗試更多! THANX! – eddy 2012-03-04 15:33:03