UILabel文本没有被更改,这是在另一个类中

时间:2016-05-04 12:31:32

标签: ios objective-c

我有两个班级

  1. 时间轴
  2. 注释
  3. 每个 CustomTableViewCell 下的时间轴类中的

    代表一个帖子,并且可以选择对帖子发表评论。要发表评论,用户必须访问评论页面评论类。当用户对其发表评论时,我希望将总评论数量传递到时间轴页面,在该页面中,它会在单元格的评论标签中显示评论数字 所以在我的评论课中,我在评论成功发布时这样做了:

    TimelineViewController *t = (TimelineViewController *)self.navigationController.viewControllers[0];
                t.updateWill = YES;
                t.updateId = self.index;
                t.updateValue =(int)self.response.responseData.count+1;
    

    cellForRowAtIndexPath 下的我的时间轴课程中,我尝试了这个:

        if(self.updateWill == YES)
            {
                NSLog(@"YES YES");
            data.commentCount= self.updateValue;
    
    
            }
            else
            {
                data.commentCount = (int)data.comments.count;
    
            }
    cell.commentLabel.text = [NSString stringWithFormat:@"%d comments",data.commentCount];
    

    NSLog(@"是是")表示逻辑有效。如果我打印self.updatevalue,它也会显示正确的结果,但标签保持不变。我做错了什么?

    更新

    在viewDidAppear上的时间轴课程

    (void)viewDidAppear:(BOOL)animated
    {
    
        [[ApiAccess getSharedInstance] setDelegate:self];
        [[[SocektAccess getSharedInstance]getSocket]setDelegate:self];
        [[[SocektAccess getSharedInstance]getSocket] reconnect];
        _chatSocket =[[SocektAccess getSharedInstance]getSocket];
    
    
        if(self.updateWill)
        {
            NSLog(@"viewDidAppear");
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.updateId inSection:0];
    
            NSLog(@"Update Value: %d",self.updateValue);
            NSLog(@"Update ID: %d",self.updateId);
    
    
    
            TimelineTableViewCell *cell = (TimelineTableViewCell *)[self.tableData cellForRowAtIndexPath:indexPath];
    
    
    
    
            WallPost *data = self.myObject[indexPath.row];
            data.commentCount = self.updateValue;
    
            [self.myObject replaceObjectAtIndex:indexPath.row withObject:data];
    
            WallPost *data2 = self.myObject[indexPath.row];
    
            NSLog(@": %d",data2.commentCount);
    
            [self.tableData reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableData reloadData];
    
    
        }
    
        self.updateWill = NO;
    }
    

    时间轴类中的cellForRowAtIndexPath:

    -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
    
        TimelineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        self.counter = 0;
    
        WallPost *data = self.myObject[indexPath.row];
    
        cell.image.userInteractionEnabled = YES;
        cell.image.tag = indexPath.row;
    
        if(self.updateWill == YES)
        {
            NSLog(@"YES YES");
            NSLog(@"Updated value : %d", (int)self.updateValue);
          data.commentCount= (int)self.updateValue;
    
    
        }
        else
        {
            data.commentCount = (int)data.comments.count;
    
        }
    

0 个答案:

没有答案