与使用UICollectionView的布局相同的电子表格 [英] Spreadsheet Like Layout Using UICollectionView

查看:95
本文介绍了与使用UICollectionView的布局相同的电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用UICollectionView创建类似布局的电子表格,其中每行显示单个对象的属性。

How can I use UICollectionView to create a spreadsheet like layout where each row displays properties of a single object.

示例:

Customer Id   First Name   Last Name   Social  Address  Phone 

以下是我使用UITableView提出的建议:

Here is what I came up with using UITableView:

funds = [[NSMutableArray alloc] init];
    columnNames = [NSArray arrayWithObjects:@"fundNumber",@"fundName",@"unitPrice",@"fundBalance",@"percentageOfAccountValue",@"futureContributionAllocation", nil];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FundCell"];

    Fund *fund = [funds objectAtIndex:[indexPath row]];

    for(NSString *columnName in columnNames)
    {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, 0, 100, 44)];

        label.backgroundColor = [UIColor clearColor];

        label.text = [fund valueForKey:columnName];

        x += label.bounds.size.width;

        [cell addSubview:label];

    }

    x = 0;

    return cell;
}

这是输出:

推荐答案

我不确定您是否能够调整标准流布局 - 您可能需要创建自己的 UICollectionViewLayout 类 - 但这应该相当简单。

I'm not sure if you'd be able to adapt the standard flow layout - you might need to create your own UICollectionViewLayout class - but this should be fairly straightforward to do.

像表视图一样,您的集合视图可以包含部分和项目:电子表格的每一行都可以是一个部分,并且那么个别元素(姓氏,社交,地址等)可以是项目。

Like a table view, your collection view can have sections and items: each row of your spreadsheet could be a section, and then the individual elements (Last Name, Social, Address, etc) could be items.

如果你想要 true 电子表格这样的功能(即,你可以水平滚动垂直)然后你将不得不建立自己的布局类。否则你可以调整现有的流程布局,虽然可以说如果你需要滚动你可以基本上实现你用表格视图后的目的。

If you want true spreadsheet like functionality (i.e, you can scroll both horizontally and vertically) then you're going to have to build your own layout class. Otherwise you may be able to adapt the existing flow layout, although arguably if you don't need to scroll you could basically achieve what you're after with a table view instead.

这篇关于与使用UICollectionView的布局相同的电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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