是否可以在UITableView中创建多个列?

时间:2022-04-10 00:07:11

I want to add more columns in my iPhone/iPad application. Is it possible to add more columns in one UITableView? Can you please suggest any sample code/block/project that using multiple columns in one UITableView? Please help me. Thanks in advance.

我想在我的iPhone / iPad应用程序中添加更多列。是否可以在一个UITableView中添加更多列?你能否建议在一个UITableView中使用多列的示例代码/块/项目?请帮帮我。提前致谢。

5 个解决方案

#1


3  

No it is not possible, in fact UITableView is badly named a represents a List more than a Table.

不,这是不可能的,实际上UITableView被命名为一个List而不是一个表。

If you want to have multiple column, one method is to create specific cells, with multiple label, and pack your data by row then column.

如果您想拥有多个列,一种方法是创建具有多个标签的特定单元格,然后按行然后按列打包数据。

#2


3  

short answer is no, but you always can create custom cell what will look like multiple columns

简短的回答是否定的,但你总是可以创建自定义单元格,看起来像多列

#3


1  

You can use my library, UIGridView.

您可以使用我的库UIGridView。

It is created with UITableView, in which UITableViewCell contains many cells inside.

它是使用UITableView创建的,其中UITableViewCell包含许多单元格。

Here is how it looks like:

它是这样的:

是否可以在UITableView中创建多个列?

#4


0  

No Yuvaraj.M we can't create. but you do something like multicolumn by adding component like label or image or button what u want or else using custom cell.

没有Yuvaraj.M我们无法创造。但你可以通过添加标签,图像或按钮等组件来实现多列,或者使用自定义单元格。

#5


0  

I've done a grid by using a table view where I have basically faked it by adding subviews to a cell. So if you for example create a cell, add three subviews to it, you can then get the items you need by doing something like this when it asks you for a cell for a specific row:

我已经使用表视图完成了一个网格,我基本上通过将子视图添加到单元格来伪造它。因此,如果您创建一个单元格,向其添加三个子视图,那么当它要求您为特定行创建单元格时,可以通过执行此类操作来获取所需的项目:

// get the items for the row (a row is one cell)
NSArray *rowItems = nil;
int startIndex = indexPath.row * NumOfItemViewsPerRow;
if (startIndex + NumOfItemViewsPerRow < [items count]) {
    rowItems = [items subarrayWithRange:NSMakeRange(startIndex, NumOfItemViewsPerRow)];
} else {
    rowItems = [items subarrayWithRange:NSMakeRange(startIndex, [items count] - startIndex)];
}

Then just after that you can loop the subviews of your row something like this:

然后,您可以循环您的行的子视图,如下所示:

[cell.itemViews enumerateObjectsUsingBlock:^(MyItemView *itemView, NSUInteger idx, BOOL *stop) {
    NSDictionary *item = [rowItems objectAtIndex:idx];
    itemView.titleLabel.text = [item valueForKey:@"title"];
};

It is a bit fiddly, but the upside is that you get row unloading for free from the table view, so you don't have to mess with your own custom grid views or anything like that.

它有点繁琐,但好处是你可以从表视图中免费卸载行,所以你不必弄乱你自己的自定义网格视图或类似的东西。

Hope that helps.

希望有所帮助。

#1


3  

No it is not possible, in fact UITableView is badly named a represents a List more than a Table.

不,这是不可能的,实际上UITableView被命名为一个List而不是一个表。

If you want to have multiple column, one method is to create specific cells, with multiple label, and pack your data by row then column.

如果您想拥有多个列,一种方法是创建具有多个标签的特定单元格,然后按行然后按列打包数据。

#2


3  

short answer is no, but you always can create custom cell what will look like multiple columns

简短的回答是否定的,但你总是可以创建自定义单元格,看起来像多列

#3


1  

You can use my library, UIGridView.

您可以使用我的库UIGridView。

It is created with UITableView, in which UITableViewCell contains many cells inside.

它是使用UITableView创建的,其中UITableViewCell包含许多单元格。

Here is how it looks like:

它是这样的:

是否可以在UITableView中创建多个列?

#4


0  

No Yuvaraj.M we can't create. but you do something like multicolumn by adding component like label or image or button what u want or else using custom cell.

没有Yuvaraj.M我们无法创造。但你可以通过添加标签,图像或按钮等组件来实现多列,或者使用自定义单元格。

#5


0  

I've done a grid by using a table view where I have basically faked it by adding subviews to a cell. So if you for example create a cell, add three subviews to it, you can then get the items you need by doing something like this when it asks you for a cell for a specific row:

我已经使用表视图完成了一个网格,我基本上通过将子视图添加到单元格来伪造它。因此,如果您创建一个单元格,向其添加三个子视图,那么当它要求您为特定行创建单元格时,可以通过执行此类操作来获取所需的项目:

// get the items for the row (a row is one cell)
NSArray *rowItems = nil;
int startIndex = indexPath.row * NumOfItemViewsPerRow;
if (startIndex + NumOfItemViewsPerRow < [items count]) {
    rowItems = [items subarrayWithRange:NSMakeRange(startIndex, NumOfItemViewsPerRow)];
} else {
    rowItems = [items subarrayWithRange:NSMakeRange(startIndex, [items count] - startIndex)];
}

Then just after that you can loop the subviews of your row something like this:

然后,您可以循环您的行的子视图,如下所示:

[cell.itemViews enumerateObjectsUsingBlock:^(MyItemView *itemView, NSUInteger idx, BOOL *stop) {
    NSDictionary *item = [rowItems objectAtIndex:idx];
    itemView.titleLabel.text = [item valueForKey:@"title"];
};

It is a bit fiddly, but the upside is that you get row unloading for free from the table view, so you don't have to mess with your own custom grid views or anything like that.

它有点繁琐,但好处是你可以从表视图中免费卸载行,所以你不必弄乱你自己的自定义网格视图或类似的东西。

Hope that helps.

希望有所帮助。