gpt4 book ai didi

ios - 在具有 2 个自定义列 UITableViewCell 的 VC 中创建 UITableView,将自定义数据从数组加载到单元格,Objective C

转载 作者:行者123 更新时间:2023-11-29 11:35:34 24 4
gpt4 key购买 nike

如何在具有 2 列的 VC 中创建以下 UITableView?因为 UITableView 只有一列。可以在 StoryBoard 中实现吗?如何添加阴影,圆角并添加图片中的模糊边框?非常感谢所有帮助或指示。

pic

已编辑

如何在 Objective C 中设置两列?我在网上找不到任何帮助,尤其是对于 Objective-C 。我认为这两列都是 UILabel

至于行,我需要在 Story Board 将 Prototype Cell 设置为 3 吗?

第一列将具有静态值:姓名、出生日期、地点。第二列将从数组中获取数据 [John Doe, 06.03.1991, New York]

我是否创建一个循环来插入数据?

回答

我关注了这个link并设法创建 2 个自定义 UILabel 列并从 NSMutableArray

插入列

我无法获得以下建议的答案,答案建议我们创建一个空用户界面,然后添加一个 Table View Cell 并将其关联回 VC。我无法让它工作。 我只是在 TableView 的原型(prototype)单元格中创建 2 个标签,然后点击上面的链接。

最佳答案

创建一个 customcell 并放置 7 个 UILabel 前 4 个标签给出名称基本设置,NAME,DOB,LOCATION 剩下的 3 个标签设置为空白并在 cell.h 文件中给出 tham 属性

 #pragma mark tableview delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [yourdataarray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"yourcustomcellname"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"yourcustomcellname" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
id object = [yourdataarray objectAtIndex:indexPath.row];

if ([object isKindOfClass:[NSMutableArray class]]) {
NSMutableArray *Array = (NSMutableArray *)object;
//your cell property use here for fatch like below
[cell.NAME setText:[NSString stringWithFormat:@"%@",[Array objectAtIndex:i]]];//here i=which index your array contain name data
}
return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return yourcustomcellheight;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}

请参阅本教程以获取 customcell https://www.appcoda.com/customize-table-view-cells-for-uitableview/

关于ios - 在具有 2 个自定义列 UITableViewCell 的 VC 中创建 UITableView,将自定义数据从数组加载到单元格,Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49614940/

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