iOS tableViewCell在不应显示时显示';T
我有一个从rails api中提取的应用程序。我在xcode中的post show页面上遇到了一个问题。我基本上会把所有与帖子相关的评论都拉出来并显示出来。为了简单起见,我在我的应用程序中的一篇帖子上贴了一条评论,其余的都没有评论。我遇到的问题是,该应用程序在每个帖子上都显示相同的评论 我检查了api,但它没有每次都返回注释,所以我不确定出了什么问题 这是我的密码: 拉评论:iOS tableViewCell在不应显示时显示';T,ios,Ios,我有一个从rails api中提取的应用程序。我在xcode中的post show页面上遇到了一个问题。我基本上会把所有与帖子相关的评论都拉出来并显示出来。为了简单起见,我在我的应用程序中的一篇帖子上贴了一条评论,其余的都没有评论。我遇到的问题是,该应用程序在每个帖子上都显示相同的评论 我检查了api,但它没有每次都返回注释,所以我不确定出了什么问题 这是我的密码: 拉评论: GFCredentialStore *credentialStore = [[GFCredentialStore a
GFCredentialStore *credentialStore = [[GFCredentialStore alloc] init];
NSString *authToken = [credentialStore authToken];
NSLog(@"%@", authToken);
__weak typeof(self)weakSelf = self;
NSNumber *postId = self.postId;
NSString *urlString = [NSString stringWithFormat:@"%s%s%@%s", kBaseURL, kPostsURL, postId, kCommentsURL];
NSLog(@"%@", urlString);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [GFPostResponseSerializer serializer];
[manager.requestSerializer setValue:authToken forHTTPHeaderField:@"auth_token"];
NSLog(@"%@", manager.requestSerializer.HTTPRequestHeaders);
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
__strong typeof(weakSelf)strongSelf = weakSelf;
strongSelf.comments = (NSArray *)responseObject;
[strongSelf.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
将注释属性分配给位于indexPath的行的单元格:
(基本上,它们是两个部分,第一个只有1个单元格,使用的是我从另一个viewController中获取的post数据,另一个部分是我的所有评论)
最后是一张显示评论的图片。蓝色注释部分在每页上显示相同。这个帖子很好用。(忽略要测试我是否显示注释的注释文本)
您是否检查是否成功更改了self.comments数组?这可能是个问题,因为在访问cellForRow中的self.commets[0]时也不会出现异常。。。method@Nils明白你的意思,你是对的。它第一次设置数组,但下一次返回完全相同的数组时,就好像没有重置它一样。知道如何修复吗?您是否查看了success:^(AFHTTPRequestOperation*operation,id responseObject)块中发生的情况?它是否获得了“正确”的注释数组?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 0){
GFPostShowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"showPostCell" forIndexPath:indexPath];
cell.groupNameLabel.text = [NSString stringWithFormat:@"Group: %@", self.groupName];
cell.postBodyLabel.text = self.postBody;
return cell;
} else {
GFCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commentCell" forIndexPath:indexPath];
NSDictionary *rootObject = self.comments[indexPath.row];
NSDictionary *comment = rootObject[@"comment"];
NSDictionary *user = comment[@"user"];
cell.usernameLabel.text = user[@"username"];
cell.commentBodyLabel.text = comment[@"body"];
return cell;
}
}