Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在swift中的一行UITableViewCell中创建多列?_Ios_Iphone_Uitableview_Swift - Fatal编程技术网

Ios 如何在swift中的一行UITableViewCell中创建多列?

Ios 如何在swift中的一行UITableViewCell中创建多列?,ios,iphone,uitableview,swift,Ios,Iphone,Uitableview,Swift,如何在一行中创建多列。 喜欢这个形象 您还可以使用gridview满足您的需求,如或 检查以下示例代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* cellIdentifier = @"gridCell"; UITableViewCell *gridCell = [tableVie

如何在一行中创建多列。
喜欢这个形象

您还可以使用gridview满足您的需求,如或

检查以下示例代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* cellIdentifier = @"gridCell";
    UITableViewCell *gridCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(gridCell == nil)
    {
        gridCell =  [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier] autorelease];
        gridCell.accessoryType = UITableViewCellAccessoryNone;
        gridCell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    NSArray* items = [_grids objectAtIndex:indexPath.section];

    int imageIndex = 0;
    int yOffset = 0;

    while (imageIndex < items.count)
    {
        int yPos = 4 + yOffset * 74;

        for(int i = 0; i < 4; ++i)
        {
            CGRect  rect = CGRectMake((18 + i * 80), yPos, 40, 40);

            UIImageView* imageView = [self gridImageRect:rect forImage:[items objectAtIndex:imageIndex]];
            [gridCell.contentView addSubview:imageView];
            [imageView release];

            rect = CGRectMake(((80 * i)-4), (yPos+44), 80, 12);

            UILabel* label = [self descriptionOfImage:imageIndex inRect:rect];
            [gridCell.contentView addSubview:label];
            [label release];

            ++imageIndex;

        }

        ++yOffset;
    }

    return gridCell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*cellIdentifier=@“gridCell”;
UITableViewCell*gridCell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(gridCell==nil)
{
gridCell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier]自动删除];
gridCell.accessoryType=UITableViewCellAccessoryNone;
gridCell.selectionStyle=UITableViewCellSelectionStyleNone;
}
NSArray*items=[\u grids objectAtIndex:indexPath.section];
int-imageIndex=0;
int-yOffset=0;
while(imageIndex
为什么不使用集合视图?您可以使用UICollectionView,否则需要编写逻辑,通过为每个值提供适当的空间,用所需的数据填充行,按照这些教程学习Swift中的集合视图需要Swift代码,不需要Objective-C代码