Objective c 如何在iPhone上创建水平UI表视图?
通常,UITableView是这样的:Objective c 如何在iPhone上创建水平UI表视图?,objective-c,iphone,uitableview,Objective C,Iphone,Uitableview,通常,UITableView是这样的: [ cell 1 ] [ cell 2 ] [ cell 3 ] [ cell 4 ] | | | | | c | c | c | | e | e | e | | l | l | l | | l | l | l | | | | | | 1 | 2 | 3 | | | | | 但我想让我自己的UITa
[ cell 1 ]
[ cell 2 ]
[ cell 3 ]
[ cell 4 ]
| | | |
| c | c | c |
| e | e | e |
| l | l | l |
| l | l | l |
| | | |
| 1 | 2 | 3 |
| | | |
但我想让我自己的UITableView如下:
[ cell 1 ]
[ cell 2 ]
[ cell 3 ]
[ cell 4 ]
| | | |
| c | c | c |
| e | e | e |
| l | l | l |
| l | l | l |
| | | |
| 1 | 2 | 3 |
| | | |
我希望用户向左和向右滑动时具有与原始UITableView类似的行为。。。我该怎么做?谢谢。我认为没有可用的控件使您能够执行此操作。你最好的办法是自己动手 简而言之,您需要将UIScrollView子类化,这将允许您拥有比屏幕上更多的单元格空间。它还将整理您的所有刷卡行为 在这个滚动视图中,您希望放置一组单元格-我希望将UIView子类化,而不是试图强制UITableViewCell对这些单元格的滚动视图进行优化
这只是如何解决问题的一个简单示例。您希望复制UITableView的多少功能?除了子类化UIScrollView之外,您可以尝试对现有UITableView应用90度旋转。但是,我不知道这将如何影响滚动,您必须将单元格视图专门化为“取消旋转”
我认为子类化UIScrollView是一个更好的选择。当涉及到委托、数据源和可重用单元时,请使用UITableView类作为指南。您拥有的只是一个以纵向显示的标准表格,但您的手机是以横向模式手持的。将每个单元格的内容旋转90度,然后将鼠标放在那里。并且一定要忽略任何方向更改通知。这里有一个项目可能也有一些用处,您自己在代码中构建类似于UITableView的东西并不太难。如果您可以找到它,WWDC09的专家级滚动视图会话有一些很棒的示例代码。可以做水平表使用UIViewController和UIView,将表的UITableView添加到控制器视图中,那么就代码而言只有一行:
- (void)viewDidLoad
{
[super viewDidLoad];
// horizontal table
// -90 degrees rotation will move top of your tableview to the left
myTableView.transform = CGAffineTransformMakeRotation(-M_PI_2);
//Just so your table is not at a random place in your view
myTableView.frame = CGRectMake(0,0, myTableView.frame.size.width, myTableView.frame.size.height);
...
如果要使用textLabel,可以使用以下选项:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.textLabel.frame = CGRectMake(0,0, cell.frame.size.width , cell.frame.size.width); // it's very important!!!You must set frame of textLabel, because you can have a problems with displaying you table;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
CGAffineTransform trans = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI_2);
cell.textLabel.transform = trans; // rotating you caption;
cell.textLabel.text = @"tra-tata";
cell.textLabel.textAlignment = UITextAlignmentCenter;
return cell;
}
我推荐,它们是github上非常棒的水平tableview项目,备受关注。有人尝试过吗?它有用吗?这听起来像是最简单的方法,但我可以想象它不起作用,因为一些内部无法改变方向。这看起来像是一个好项目,不幸的是它是在GNU GPL下许可的,这使得它很难甚至不可能在应用商店应用程序中使用。不再是在GPL下,现在它是麻省理工学院!这是一个简单而令人敬畏的想法……!!::)这很好,但单元格内容也会旋转以使单元格恢复正常,只需使单元格朝相反方向旋转90度即可。可在此处找到完整的教程: