无法在ViewController中使用两个TableView设置自定义UITableViewCell属性

时间:2013-12-05 20:20:10

标签: ios iphone objective-c uitableview

在我正在创建的应用的评论控制器中,我有两个tableView:注释表和尝试标记其他用户时显示的表。

所有数据都正确加载,但是当我尝试创建自定义单元格(ExploreCell)时,我的自定义属性(UILabel和UIImageView)不会显示。为了测试的缘故,我尝试将细胞的背景颜色链接起来,并将它们设置为黑色。

我已经注册了所有正确的笔尖,我无法弄清楚为什么会这样。

-(UITableViewCell *)tableView:(UITableView *)tableViewItem cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellforrow");
if (tableViewItem == self.tableView) {
    static NSString *identifier = @"Cell";
    CommentCell *cell = (CommentCell *)[tableViewItem dequeueReusableCellWithIdentifier:identifier];


    if (fetched == YES) {
        [cell.usernameLabel setTitle:[[[commentArray objectAtIndex:indexPath.row]objectForKey:@"user"] valueForKey:@"username"] forState:UIControlStateNormal];
        cell.usernameLabel.tag = indexPath.row;
        [cell.usernameLabel addTarget:self action:@selector(goToUser:) forControlEvents:UIControlEventTouchUpInside];
        [cell.profilePicture setImage:[profPicDictionary objectForKey:[[[commentArray objectAtIndex:indexPath.row]objectForKey:@"user"] valueForKey:@"username"]]];
    }

    [cell.commentLabel setUserInteractionEnabled:YES];
    [cell.commentLabel setScrollEnabled:NO];
    [cell.commentLabel setEditable:NO];
    [cell.commentLabel setSelectable:YES];
    [cell.commentLabel setDelegate:self];
    cell.commentLabel.attributedText = [self getAttributedText:[[commentArray objectAtIndex:indexPath.row]valueForKey:@"comment"]];
    cell.commentLabel.contentInset = UIEdgeInsetsMake(0, -5, 0, 0);
    [cell.commentLabel setFrame:CGRectMake(cell.commentLabel.frame.origin.x, cell.commentLabel.frame.origin.y, 257, 10)];
    [cell.commentLabel sizeToFit];

    NSDate *createdAt = [[commentArray objectAtIndex:indexPath.row]valueForKey:@"createdAt"];

    cell.createdLabel.text = [self setCreatedTimestamp:createdAt];


    [cell.usernameLabel.titleLabel setFont:[UIFont fontWithName:@"Radikal-Thin" size:14.0f]];
    [cell.commentLabel setFont:[UIFont fontWithName:@"Radikal-Thin" size:15.0f]];
    [cell.createdLabel setFont:[UIFont fontWithName:@"Radikal-Thin" size:14.0f]];

    return cell;
} else {
    NSLog(@"explore");
    static NSString *identifier = @"userCell";
    ExploreCell *tagCell = (ExploreCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
    if (!tagCell) {
        tagCell = [[ExploreCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"userCell"];
    }
    if (tableData.count >> 0) {
        [tagCell.usernameLabel setText:[[tableData objectAtIndex:indexPath.row]valueForKey:@"username"]];
        [tagCell.profilePicture setImage:[profPicDictionary objectForKey:[[tableData objectAtIndex:indexPath.row]valueForKey:@"username"]]];
        tagCell.backgroundColor = [UIColor blackColor];
    }
    NSLog(@"tagcell: %@",tagCell);
    return tagCell;
}

}

1 个答案:

答案 0 :(得分:0)

编辑else部分中的以下行,你应该好好去

ExploreCell *tagCell = (ExploreCell *)[tableViewItem dequeueReusableCellWithIdentifier:identifier];

更改此行,如果您仍然发现任何问题,请告诉我。