如何在 UITableView 中显示多列? [英] How to display multiple columns in a UITableView?

查看:41
本文介绍了如何在 UITableView 中显示多列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 UITableView 中显示多列.

I want to display multiple columns in a UITableView.

例如:

表格视图

   FName        LName    Age

   -----        -----    ---

   Abby         Michale   34   

推荐答案

您可以在 IB 中定义一个自定义单元格,它将包含 3 个标签和函数:

You can define a custom cell in IB, which will contain 3 labels and in function:

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

         static NSString *DetailCellIdentifier = @"DetailCell";

         UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:DetailCellIdentifier];

         if (cell == nil) {
            NSArray *cellObjects = [[NSBundle mainBundle] loadNibNamed:@"DetailCell" owner:self options:nil];
            cell = (UITableViewCell*) [cellObjects objectAtIndex:0];
        }

        // setup your cell
     }

当你在 IB 中定义单元格时,给每个标签一个标签,所以当你需要在那里放一个文本时,你可以像这样通过标签检索它:

when you define the cell in IB give each label a tag, so when you need to put a text there you can retrieve it by tag like this:

        label = (UILabel *)[cell viewWithTag:NAME_TAG];
        label.text = myObject.name; 

并用其他 2 个标签重复此操作.标签是唯一编号.

and repeat this with other 2 labels. The tag is a unique number.

改为使用此代码//设置您的单元格注释

Put this code instead //setup your cell comment

这篇关于如何在 UITableView 中显示多列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆