iOS:自定义UITableViewCell,包含3个字段

时间:2022-11-13 10:06:00

I would like to create a custom UITableViewCell with 3 fields. I would like each of the fields to be horizontally scrollable.

我想创建一个包含3个字段的自定义UITableViewCell。我希望每个字段都可以水平滚动。

    Field1   Field2   Field3
    ======   ======   ======
    Label1 | Label2 | [graphics: lines, etc.]

My question: What is the right way to implement this?

我的问题:实施这个的正确方法是什么?

  1. Do I create a custom UIViewController with 3 UITableViews?
  2. 我是否使用3个UITableViews创建自定义UIViewController?

  3. Do I create a single UITableView with UITableViewCells that contain 3 UITableViewCell subviews?
  4. 我是否使用包含3个UITableViewCell子视图的UITableViewCells创建单个UITableView?

  5. Other?

Any examples would be great.

任何例子都会很棒。

Thank you!

4 个解决方案

#1


0  

You might need to go with Other option, with a single UIViewController with a single UITableView.

你可能需要使用Other选项,只需一个带有单个UITableView的UIViewController。

A Custom UITableViewCell with three UIScrollViews would help you.

具有三个UIScrollViews的自定义UITableViewCell可以帮助您。

#2


1  

Create your own custom TableViewCell inside that firstly put UiScrollView. inside that 2 Uilabel and 1 UiView i think(acoording to your question).off the vertical scrolling of uiscrollView through intefacebuilder. set the contentSize property of uiscrollView.be sure your widhth of ContentSize of UiScrollView greater than your cell width.

在里面创建自己的自定义TableViewCell,首先放入UiScrollView。我认为2 Uilabel和1 UiView内部(根据你的问题)。通过intefacebuilder,uiscrollView的垂直滚动。设置uiscrollView.be的contentSize属性,确保你的UiScrollView的ContentSize的宽度大于你的单元格宽度。

#3


0  

I would create a single UITableView with dequeued UITableViewCell's that contains UIScrollViews, UIlabel and UIImageView's

我将使用出列的UITableViewCell创建一个包含UIScrollViews,UIlabel和UIImageView的UITableView。

#4


0  

Mr. nilweed. Here it will help you to add three fields in UITableView cells. I don't know to scroll the tableview horizontally.

尼尔维德先生。在这里,它将帮助您在UITableView单元格中添加三个字段。我不知道水平滚动tableview。

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

if (cell == nil) 
{ 
cell = [[[UITableViewCell alloc]
                            initWithStyle:UITableViewCellStyleDefault 
                            reuseIdentifier: CellIdentifier] autorelease];

NSString *cellIconName = [[self cellIcon] objectAtIndex:[indexPath row]];
cellImage=[UIImage imageNamed:cellIconName];

cell.imageView.image=cellImage;

UILabel *labelOne = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 60, 20)];
labelOne.tag = 100;
[cell.contentView addSubview:labelOne];
[labelOne release];

UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(80, 10, 60, 20)];
labelTwo.tag = 101;
[cell.contentView addSubview:labelTwo];
[labelTwo release];

UILabel *labelThree = [[UILabel alloc]initWithFrame:CGRectMake(160, 10, 150, 20)];
labelTwo.tag = 103;
[cell.contentView addSubview:labelTwo];
[labelTwo release];

}

UILabel *labelOne = (UILabel *) [cell.contentView viewWithTag:100];
labelOne.text = @"Label One";

UILabel *labelTwo = (UILabel *) [cell.contentView viewWithTag:101];
labelTwo.text = @"Label Two";

UILabel * labelThree = (UILabel *) [cell.contentView viewWithTag:101];
labelThree.text = @"Label Three";
 

return cell;
}

I hope it will help you a little bit.

我希望它会对你有所帮助。

Thanks.

#1


0  

You might need to go with Other option, with a single UIViewController with a single UITableView.

你可能需要使用Other选项,只需一个带有单个UITableView的UIViewController。

A Custom UITableViewCell with three UIScrollViews would help you.

具有三个UIScrollViews的自定义UITableViewCell可以帮助您。

#2


1  

Create your own custom TableViewCell inside that firstly put UiScrollView. inside that 2 Uilabel and 1 UiView i think(acoording to your question).off the vertical scrolling of uiscrollView through intefacebuilder. set the contentSize property of uiscrollView.be sure your widhth of ContentSize of UiScrollView greater than your cell width.

在里面创建自己的自定义TableViewCell,首先放入UiScrollView。我认为2 Uilabel和1 UiView内部(根据你的问题)。通过intefacebuilder,uiscrollView的垂直滚动。设置uiscrollView.be的contentSize属性,确保你的UiScrollView的ContentSize的宽度大于你的单元格宽度。

#3


0  

I would create a single UITableView with dequeued UITableViewCell's that contains UIScrollViews, UIlabel and UIImageView's

我将使用出列的UITableViewCell创建一个包含UIScrollViews,UIlabel和UIImageView的UITableView。

#4


0  

Mr. nilweed. Here it will help you to add three fields in UITableView cells. I don't know to scroll the tableview horizontally.

尼尔维德先生。在这里,它将帮助您在UITableView单元格中添加三个字段。我不知道水平滚动tableview。

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

if (cell == nil) 
{ 
cell = [[[UITableViewCell alloc]
                            initWithStyle:UITableViewCellStyleDefault 
                            reuseIdentifier: CellIdentifier] autorelease];

NSString *cellIconName = [[self cellIcon] objectAtIndex:[indexPath row]];
cellImage=[UIImage imageNamed:cellIconName];

cell.imageView.image=cellImage;

UILabel *labelOne = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 60, 20)];
labelOne.tag = 100;
[cell.contentView addSubview:labelOne];
[labelOne release];

UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(80, 10, 60, 20)];
labelTwo.tag = 101;
[cell.contentView addSubview:labelTwo];
[labelTwo release];

UILabel *labelThree = [[UILabel alloc]initWithFrame:CGRectMake(160, 10, 150, 20)];
labelTwo.tag = 103;
[cell.contentView addSubview:labelTwo];
[labelTwo release];

}

UILabel *labelOne = (UILabel *) [cell.contentView viewWithTag:100];
labelOne.text = @"Label One";

UILabel *labelTwo = (UILabel *) [cell.contentView viewWithTag:101];
labelTwo.text = @"Label Two";

UILabel * labelThree = (UILabel *) [cell.contentView viewWithTag:101];
labelThree.text = @"Label Three";
 

return cell;
}

I hope it will help you a little bit.

我希望它会对你有所帮助。

Thanks.