【问题标题】:Changing frame of the tableView causing trouble in my app更改 tableView 的框架导致我的应用出现问题
【发布时间】: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


【解决方案1】:

听起来您的图像定位已关闭。图像的 x 和 y 位置是什么?我想您会发现您的图像在旋转时位于包含视图框架之外,因此您看不到它们。

但是,您说您正在向滚动视图添加表格视图?你不应该这样做。

【讨论】:

  • 你似乎是对的......我会检查这个。但是你能告诉我为什么我不应该在我的scrollView上添加一个tableView吗?谢谢.. +1 你的回答....
  • 我还用一些代码 sn-ps 编辑了我的问题。请看一下...
  • UITableView 是 UIScrollView 的子类。
  • 我怀疑你想要一个滚动的东西在另一个滚动的东西里面。你的细胞有多高?尝试将图像定位在 x=0 y=0。图片出框的方向是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
  • 2017-02-13
相关资源
最近更新 更多