How to display multiple columns in a UITableView?

匿名 (未验证) 提交于 2019-12-03 01:29:01

问题:

I want to display multiple columns in a UITableView.

For Example:

TableView

   FName        LName    Age     -----        -----    ---     Abby         Michale   34    

回答1:

You can define a custom cell in IB, which will contain 3 labels and in function:

    - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {           static NSString *DetailCellIdentifier = @"DetailCell";           UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:DetailCellIdentifier];           if (cell == nil) {             NSArray *cellObjects = [[NSBundle mainBundle] loadNibNamed:@"DetailCell" owner:self options:nil];             cell = (UITableViewCell*) [cellObjects objectAtIndex:0];         }          // setup your cell      } 

when you define the cell in IB give each label a tag, so when you need to put a text there you can retrieve it by tag like this:

        label = (UILabel *)[cell viewWithTag:NAME_TAG];         label.text = myObject.name;  

and repeat this with other 2 labels. The tag is a unique number.

Put this code instead //setup your cell comment



回答2:

I think the correct way of doing this is UICollectionView. Started with UITableView and finally failed at some point due to unexpected behavior while trying to implement scrolling both left-right and up-down.

Please check this awesome post for a complete and up-to-date solution: http://www.brightec.co.uk/blog/uicollectionview-using-horizontal-and-vertical-scrolling-sticky-rows-and-columns

Result will be like this:



回答3:

I have created UIGridView. I believe your problem can be solved using the same technique.

You can learn the source code of UIGridView. The code is really short.



回答4:

Create a custom UIView subclass containing, say, three UILabel elements as subviews. Then set the cell's contentView property to this custom view.



回答5:

add three labels as sub viewsinto uitableview cell's content.then assign apprrpriate values to it eg:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  static NSString *CellIdentifier = @"Cell";  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) {     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];   }  //frame should be set accordingly(means should be framed accordingly).  UILabel *l1=[[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 100,100)];  UILabel *l2=[[UILabel alloc]initWithFrame:CGRectMake(110,10,100,80)]; UILabel *l3=[[UILabel alloc]initWithFrame:CGRectMake(115,60,100,50)];  [cell.contentView addSubview:l1]; [cell.contentView addSubview:l2]; [cell.contentView addSubview:l3];  return cell;  } 


回答6:

Bit late to the party, but we've open sourced our fully featured table component:

https://github.com/flexicious/iOSDataGrid

Some screenshots:

http://www.ioscomponents.com/Home/IOSDataGrid

Feel free to use!



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!