<分区>
标签 ios
我创建了 UITableViewCell
的子类并添加了两个相同的 UIView
具有完全相同的格式。
MyTableViewCell:
UIView *leftView = [[UIView alloc ] initWithFrame:CGRectMake(0, 0, 160, 100)];
UIView *rightView = [[UIView alloc ] initWithFrame:CGRectMake(160, 0, 160, 100)];
[self.contentView addSubview:leftView];
[self.contentView addSubview:rightView];
每次我需要在 indexPath.row
时分配两个值表示仅一个索引。这是我当前的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row %2) {
cell.label1.text = [array objectAtindex:indexPath.row] objectForKey:@"name"];
cell.label2.text =[array objectAtindex:indexPath.row] objectForKey:@"name"];
}
}
单元格布局:
|------------|--------------|
| 1 | 2 |
-----------------------------
| 3 | 4 |
-----------------------------
| 5 | 6 |
-----------------------------
结果是单元格 2、3、6 为空,单元格 1、4、5 已填充。我不知道如何将数据填充到两个相同的 UIView 中。
最佳答案
假设您的数组
包含的项目数量恰好是表格行数的两倍,它应该像这样工作:
NSUInteger indexForField1 = indexPath.row * 2;
NSUInteger indexForField2 = indexPath.row * 2 + 1;
cell.label1.text = [array objectAtindex:indexForField1] objectForKey:@"name"];
cell.label2.text =[array objectAtindex:indexForField2] objectForKey:@"name"];
关于ios - 寻找有关如何将数据填充到具有两个 uiview 的 uitableviewcell 中的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9725089/