开发者

Changing frame of the tableView causing trouble in my app

i want to show a gallery kind of thing with the help of a tableView in my iPad app. 5 images should be shown in portrait mode and 8 in landscape mode. To achieve this functionality i have done the following.

1- I'v taken a tableView and rotated it 90 degrees

2- I again rotated the tableView cell by -90 degrees so that i can place my images in it.

3- I placed some images in my TableView and added it to my scrollView.

4 - i have set frames for my tableView differently for portrait and landscape....

if(UIInterfaceOrientationIsPortrait(self.interfaceOrnetation)){
    myTableView.frame = CGRectMake(0,0,768,200);

}
 else{
   myTableView.frame = CGRectMake(0,0,1024,200);
}

5 - i am also changing the frames with the above lines in didRotateFrominterfaceOrientationmethod.

i am using the following code to load the images in the 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 *thumbnailImageV开发者_开发技巧iew = [[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;
    }

The frames works just fine for the first time. But, when i rotate the device, the images in the tableView are not getting displayed. I dont know where the problem lies.. Again if i dont changes the frame after rotation, it works fine and all the images are getting displayed... IS there something i am missing in the tableView???


It sounds like your positioning of the images is off. What is the x and y positions of the images? I think you'll find your images are outside the containing view frame when rotating hence you can't see them.

However, you say that you are adding a tableview to a scrollview? you shouldn't do so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜