如何在UITableView中显示多个列?

13 iphone uitableview

我想在UITableView中显示多个列.

例如:

的TableView

   FName        LName    Age

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

   Abby         Michale   34   
Run Code Online (Sandbox Code Playgroud)

tur*_*enh 20

我认为这样做的正确方法是UICollectionView.从UITableView开始,最后由于在尝试实现左右和上下滚动时的意外行为而失败.

请查看这篇精彩文章,了解完整的最新解决方案:http: //www.brightec.co.uk/blog/uicollectionview-using-horizo​​ntal-and-vertical-scrolling-sticky-rows-and-columns

结果将是这样的:

在此输入图像描述


Nav*_*mon 12

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

    - (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
     }
Run Code Online (Sandbox Code Playgroud)

当您在IB中定义单元格时,为每个标签添加一个标签,因此当您需要在其中放置文本时,您可以通过标签检索它,如下所示:

        label = (UILabel *)[cell viewWithTag:NAME_TAG];
        label.text = myObject.name; 
Run Code Online (Sandbox Code Playgroud)

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

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