显示两列结果

时间:2011-07-04 18:17:57

标签: objective-c ios ipad

我有一个有三个属性的数组 图片 名称 日期

我想在两列中显示它,而不是在一个只给我一列的表视图中。我怎么能这样做?

谢谢,

3 个答案:

答案 0 :(得分:2)

子类UITableViewCell - 例如MyUITableViewCell,然后将两个UILable添加到新单元格中。 根据需要放置它们(例如,每个单元的宽度的一半,一个对齐左,一个右对齐)。

然后cellForRowAtIndexPath的dataSource中的UITableView方法,而不是创建UITableViewCell的新实例,创建MyUITableViewCell的实例并设置两个{{} 1}} s'要显示的数据的文本。

答案 1 :(得分:1)

如果你想使用界面构建器,你可以在UITableViewCell中布局你想要的视图,用不同的数字标记它们然后使用这样的东西:

- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {

    NSArray* nibViews =  [[NSBundle mainBundle] loadNibNamed:@"TableCells" owner:self options:nil];
    UITableViewCell *cell = [nibViews objectAtIndex:1];

    return cell;

}


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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [self getCellContentView:CellIdentifier];
    }

    Account *acc = [accountManager.accounts objectAtIndex:indexPath.row];
    UILabel *title = (UILabel*)[cell viewWithTag:1];
    UILabel *counters = (UILabel*)[cell viewWithTag:3];

    title.text = acc.title;
    counters.text = [acc statusText];

    return cell;
}

答案 2 :(得分:0)

iPhone开发中只有rowssections。如果您需要列,则应将图片,名称和日期添加为subviews

UITableViewCell
UITableViewCell *cell ; //  allocate this
[cell addSubview: comboView]; // where comboView has 3 views in it.  
相关问题