gpt4 book ai didi

ios - ASIHTTPREQUEST 用 json 数据填充 uitableview

转载 作者:行者123 更新时间:2023-12-01 16:49:20 26 4
gpt4 key购买 nike

我已经阅读了几个小时,但我无法弄清楚为什么我的表不会用更新的数据重新加载自己,这是我以 block 形式提出的请求:

 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;
}

任何帮助表示赞赏,这真的很令人沮丧:(

最佳答案

您是否检查过 json 数组是否已更新?并且您在编译指示部分中使用了 json 数组作为属性(self.json),而不是在内部 block 中。

关于ios - ASIHTTPREQUEST 用 json 数据填充 uitableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17463354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com