uitableview如何将每行添加两个cell,数据是后台传输的

clipboard.png
这个uitableview如何在每行添加两列数据,在线等

阅读 7.6k
4 个回答

思路一:如一楼,使用UICollectionView,可以一行放置2个单元Cell
思路二:继续使用UITableView,在一个单元格中放入两个View

用UICollectionView

还是collection view好啊,直接,两个view不行。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return (List.count)/2+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    NSUInteger row=[indexPath row];
    
    UIView *v1 = cell.leftView;
    UIView *v2 = cell.rightView;
    GoodsList *subInfo=nil;
    
    for (NSInteger i = 0; i < 2; i++)
    {
        //奇数
        if (row*2+i >List.count - 1)
        {
            v2.hidden = YES;
            break;
        }
        subInfo = [List objectAtIndex:row*2 + i];
        if (i==0)
        {
            v1.hidden = NO;
         }else{
             v2.hidden = NO;
         }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题