2012-01-08 35 views
0

我刚刚安装了与ios5的xcode 4.2.1,我尝试使用json。json ios5在屏幕上没有任何东西

这是我的代码

-(void)start 

{ 
    responseData = [[NSMutableData data]retain]; 
    membreArray = [NSMutableArray array]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http:******.php"]]; 
    [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

} 
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [responseData setLength:0]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [responseData appendData:data]; 
} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSLog(@"error %@",error); 
} 

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

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

    [responseData release]; 

    jsonArray = [responseString JSONValue]; 

    NSLog(@"array %@",jsonArray); 



} 
NSLog(@"array %@",jsonArray);我可以看到所有的记录,一切正常

。但在我的桌面屏幕上没有任何东西。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [jsonArray count]; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    // Configure the cell. 

    NSDictionary *dico = [self.jsonArray objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [dico objectForKey:@"name"]; 


    return cell; 
} 

上的Xcode 3此代码的工作,但不是在Xcode 4

萨姆帮助请。

回答

0

当你完成加载数据后,你需要告诉你的tableview重新加载。我没看到你的代码。尝试是这样的:

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

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

    [responseData release]; 

    jsonArray = [responseString JSONValue]; 

    NSLog(@"array %@",jsonArray); 
    /* This tells your tableView to reload */ 
    [tableView reloadData]; 
} 

此外,请确保您的TableView通过一个IBOutlet连接的设计师。否则你的命令将会充耳不闻。