调整单元格字段-目标C



我有一个动态设置的table view controller,用于填充新闻类型提要。我有麻烦连接一个类到另一个设置文本,图像等…

要点如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"timelineCell";
    FBGTimelineCell *cell = (FBGTimelineCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.text = [self.googlePlacesArrayFromAFNetworking[indexPath.row] objectForKey:@"message"]; <!-- here is where I want to for example, set the title to the message within this array.
    if (!cell)
    {
        cell = [[FBGTimelineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [cell initTimelineCell];
    }
    UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", indexPath.row]];
    cell.photoView.image = img;
    return cell;
}

FBH... init函数:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        cellContentView = [[UIView alloc] initWithFrame:CGRectMake(10, 5, 300, 440)];
        cellContentView.backgroundColor = [UIColor whiteColor];
        photoView = [[FBGTimelinePhotoView alloc] initWithFrame:CGRectMake(5, 102, 310, 310)];
        photoView.backgroundColor = [UIColor darkGrayColor];
        [photoView setUserInteractionEnabled:YES];
        UIView *profilePic = [[UIView alloc] initWithFrame:CGRectMake(9, 9, 30, 30)];
        profilePic.backgroundColor = [UIColor darkGrayColor];
        UILabel *usernameLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 9, 222, 18)];
        usernameLabel.font = [UIFont systemFontOfSize:14.0];
        usernameLabel.text = @"Username";
        UILabel *timestampLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 25, 222, 17)];
        timestampLabel.font = [UIFont systemFontOfSize:12.0];
        timestampLabel.text = @"3 hours ago";
        timestampLabel.textColor = [UIColor lightGrayColor];
        UILabel *statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(9, 50, 283, 41)];
        statusLabel.font = [UIFont systemFontOfSize:15.0];
        statusLabel.text = @"Status..status..status..status..status..status..status..status..status..status..status..status..status..status..status..";
        statusLabel.numberOfLines = 2;
        statusLabel.lineBreakMode = NSLineBreakByWordWrapping;
        UILabel *likeLabel = [[UILabel alloc] initWithFrame:CGRectMake(9, 413, 32, 21)];
        likeLabel.font = [UIFont systemFontOfSize:13.0];
        likeLabel.text = @"Like";
        UILabel *commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(113, 413, 74, 21)];
        commentLabel.font = [UIFont systemFontOfSize:13.0];
        commentLabel.text = @"Comment";
        UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(246, 413, 46, 21)];
        shareLabel.font = [UIFont systemFontOfSize:13.0];
        shareLabel.text = @"Share";
        [self addSubview:cellContentView];
        [self addSubview:photoView];
        [cellContentView addSubview:profilePic];
        [cellContentView addSubview:usernameLabel];
        [cellContentView addSubview:timestampLabel];
        [cellContentView addSubview:statusLabel];
        [cellContentView addSubview:likeLabel];
        [cellContentView addSubview:commentLabel];
        [cellContentView addSubview:shareLabel];

    }
    return self;
}

因此,如果可能的话,我需要能够在cellForRowAtIndexPath内的单元格内设置单元格文本和不同的视图,以便在FB..init函数中设置每个单元格。

建议,想法?

您应该为需要在cellFroRowAtIndexPath中访问的每个UI元素创建属性(在FBGTimelineCell类中),然后您可以使用cell.propertyName访问它们。

您可以为每个单元格中需要更改的所有动态值创建属性。这些属性可以在cellForRowAtIndexPath方法中设置。

。细胞。statusText = [NSString stringWithFormat:@"%@ is rocking!!", indexPath.row];

像statusText这样的公共属性,你可以添加所有期望被动态添加的ui元素。

希望有帮助。欢呼。

最新更新