2012-03-04 59 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