如何使用 UICollectionView 创建类似于布局的电子表格,其中每行显示单个对象的属性。
例子:
Customer Id First Name Last Name Social Address Phone
这是我使用 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;
}
这是输出: