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

标签 ios objective-c uitableview

如何在具有 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/

相关文章:

ios - iOS swift 上的 SIGABRT ABORT 崩溃

objective-c - 如何以编程方式设置代理设置

objective-c - '无法使标识符为 <addressCell> 的单元格出列

ios - 谷歌地图 sdk 在 iPhone 中显示方向

iphone - 企业许可证的应用内购买功能的相关性

objective-c - NSTimer 的精度

ios - 符合协议(protocol)的类 - 编译时检查

swift - 可以将标签添加到动态原型(prototype) UITableView 中的静态单元格吗? ( swift )

iphone - 应用程序崩溃并发送到已释放实例的错误消息

ios - 如何设置我的 iOS Storyboard以像 Instagram Stream 一样弹跳?