2

私は何時間も読んでいますが、更新されたデータでテーブルが再ロードされない理由がわかりません。ブロック形式で行っているリクエストは次のとおりです。

 ASIHTTPRequest *_request= [ASIHTTPRequest requestWithURL:url];
__weak ASIHTTPRequest *request = _request;
request.requestMethod = @"POST";
[request addRequestHeader:@"Content-Type" value:@"application/json"];


[request setDelegate:self];
[request setCompletionBlock:^{
    NSString *responseString = [request responseString];
    NSData *responseData = [request responseData];
    NSLog(@"Response: %@", responseString);
    NSError* error;
    json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
    NSLog(@"request finished");
    [CommMTable reloadData];


}];
[request setFailedBlock:^{
    NSError *error = [request error];
    NSLog(@"Error: %@", error.localizedDescription);
}];

[request startAsynchronous];

json オブジェクトはコンソールに出力されるので正常に取得されますが、テーブルは更新されません!

これが私のテーブルプラグマセクションです

(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

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


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier=@"Cell";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    NSDictionary *tempDictionary= [self.json objectAtIndex:indexPath.row];



    if(cell==nil) {
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }


    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
    cell.textLabel.text = [tempDictionary objectForKey:@"title"];


    return cell;
}

どんな助けでも大歓迎です、これは本当にイライラします:(

4

3 に答える 3

0

json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

これを行うと、json 配列は のスコープでのみ使用可能になりますsetCompletionBlock

json配列を合成したので、次のように割り当てる必要があります

self.json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

これも機能しない場合は、json の形式が正しいかどうか、および .json で json を適切に解析しているかどうかを確認してくださいcellForRowAtIndexPath

于 2013-07-05T08:58:25.460 に答える