Quantcast
Channel: C++博客-所有随笔
Viewing all articles
Browse latest Browse all 7882

原:自定义UITableViewCell的旋转问题

$
0
0
创建:2012.08.20
自定义UITableViewCell的旋转时,无法旋转。解决办法有3种:
第一种:
1)在didRotateFromInterfaceOrientation中,调用reloadData
2)准备2个xib文件,一个是横屏,一个是竖屏。
3)  在cellForRowAtIndexPath中,根据不同的方向,选择不同的xib。注意,不使用dequeueReusableCellWithIdentifier,而是每次都创建新的cell。
第二种:
1)在didRotateFromInterfaceOrientation中,调用reloadData
2)在cellForRowAtIndexPath中,根据不同的方向,改变frame的值。注意:不需要改变cell的值,只需要改变cell里面的view的值。例如:

    UIView *contentView = [cell.subviews objectAtIndex:0];    

    if (UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))

    {

        contentView.frame = CGRectMake(0, 0, 480, cell.frame.size.height);

    }

    else {

        contentView.frame = CGRectMake(0, 0, 320, cell.frame.size.height);        

    } 


第三种:

不使用自定义的cell,而是使用普通的cell,然后使用contentView来进行配置。

注意:这种方法我没有试验过,不知道是否可以,只是猜测而已。因为普通的cell的旋转是没有问题的。



+++++


佳为好友 2012-12-29 10:49 发表评论

Viewing all articles
Browse latest Browse all 7882

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>