gpt4 book ai didi

ios - 调整单元格字段 - objective-c

转载 作者:行者123 更新时间:2023-11-28 22:13:42 24 4
gpt4 key购买 nike

我有一个动态设置 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 中的单元格内设置单元格文本和不同 View 如果可能,对于 FB..init 中设置的每个单元格功能。

建议、想法?

最佳答案

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

关于ios - 调整单元格字段 - objective-c ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22290643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com