【发布时间】:2011-08-04 11:40:02
【问题描述】:
我想在我的 iPad 应用程序中借助 tableView 来展示类似画廊的东西。应以纵向模式显示 5 张图像,以横向模式显示 8 张图像。为了实现这个功能,我做了以下事情。
1- 我取了一个 tableView 并将其旋转了 90 度
2- 我再次将 tableView 单元格旋转了 -90 度,以便可以将图像放入其中。
3- 我在 TableView 中放置了一些图像并将其添加到我的 scrollView。
4 - 我为我的 tableView 设置了不同的纵向和横向框架....
if(UIInterfaceOrientationIsPortrait(self.interfaceOrnetation)){
myTableView.frame = CGRectMake(0,0,768,200);
}
else{
myTableView.frame = CGRectMake(0,0,1024,200);
}
5 - 我还在didRotateFrominterfaceOrientationmethod 中使用上述行更改框架。
我正在使用下面的代码来加载tableView中的图片
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (cell==nil) {
NSLog(@"count ");
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewStylePlain reuseIdentifier:cellIdentifier] autorelease];
UILabel *pageNumberLabel = [[UILabel alloc] init];
pageNumberLabel.tag = 10;
pageNumberLabel.frame = CGRectMake(35, -10, 100, 50);
[cell.contentView addSubview:pageNumberLabel];
UIImageView *thumbnailImageView = [[UIImageView alloc] init];
thumbnailImageView.tag = 20;
thumbnailImageView.frame = CGRectMake(10, 35, 140, 160);
[cell.contentView addSubview:thumbnailImageView];
}
id<PageDataSource> pd = [kbDataSource pageAtIndex:indexPath.row];
UILabel *pageLabel = [cell viewWithTag:10];
pageLabel.backgroundColor = [UIColor clearColor];
pageLabel.text = [NSString stringWithFormat:@"Page %d",indexPath.row+1];
pageLabel.textColor = [UIColor whiteColor];
UIImageView *thumbnail = [cell viewWithTag:20];
thumbnail.image = [pd thumbnailImageForPageNumber:indexPath.row+1];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.transform = CGAffineTransformMakeRotation(M_PI/2);
return cell;
}
框架第一次工作得很好。但是,当我旋转设备时,tableView 中的图像没有显示出来。我不知道问题出在哪里。再次,如果我在旋转后不更改框架,它可以正常工作并且所有图像都被显示... tableView 中是否缺少我的东西???
【问题讨论】:
-
什么都别做,试试吧!因为ipad会自动设置它的tableviews
-
您还设置了方向功能中的图像视图或滚动视图。
-
@ganesh:我不认为 iPad 会在这里做任何事情...您需要设置 tableView 的高度,以便增加可见单元格的数量
-
@ram: 不,除了在旋转功能中更改 tableView 的框架外,我什么也没做
标签: iphone ios ipad uitableview