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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

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

//    NSLog(@"msgcnt123 %@\n",[messageCount objectAtIndex:indexPath.row]);

    NSArray *seperateArray = [[clist objectForKey:[[clist allKeys]objectAtIndex:indexPath.row]]componentsSeparatedByString:@"@"];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//    NSLog(@"key %@\n",[[clist allKeys]objectAtIndex:indexPath.row]);

    cell.textLabel.text = [seperateArray objectAtIndex:0];
//    cell.textLabel.text = [contactlist objectAtIndex:indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

//    NSLog(@"sep %@\n",seperateArray);


    if (![[seperateArray objectAtIndex:1] isEqualToString:@"0"]) {
        NSLog(@"msgCount %@\n",[seperateArray objectAtIndex:1]);
        lblCnt = [[UILabel alloc]initWithFrame:CGRectMake(260, 13, 20, 20)];
        lblCnt.backgroundColor = [UIColor lightGrayColor];
        lblCnt.textColor = [UIColor blackColor];
        lblCnt.text = [seperateArray objectAtIndex:1];
        lblCnt.textAlignment = UITextAlignmentCenter;
        lblCnt.layer.masksToBounds = YES;
        lblCnt.layer.cornerRadius = 2.0f;
        [cell.contentView addSubview:lblCnt];
        lblCnt.tag = 1000;

    }
    else
    {
        /*NSLog(@"msgCount1 %@\n",[seperateArray objectAtIndex:1]);
        [lblCnt removeFromSuperview];
        lblCnt.hidden = YES;*/
        for (UIView *view in [cell.contentView subviews]) 
        {
            if (view.tag == 1000) 
            {
              [view removeFromSuperview];
            }
        }

    }

    return cell;
}

UITableViewにラベル付きの連絡先名を表示しています。各連絡先の受信メッセージ数を表示するラベル。ビュー名はchatViewcontrollerです。そのビューにいる場合、そのラベル数は更新されません。例:連絡先名「John」の場合ラベルカウントは「2」です。ジョンがラベルカウントを「3」として更新する必要があるというメッセージを受信した場合、それは発生していません。別のビューから移動すると更新されます。tableViewchatviewController自体を更新することはできますか?

4

1 に答える 1

1

datasource( clist) を更新したことを確認してから呼び出します [tableview reloadData]

于 2013-02-15T13:22:38.663 に答える