在表格视图中重新排列对象以适应iPad的不同方向 [英] Rearrange object in table view for different orientation of iPad

查看:105
本文介绍了在表格视图中重新排列对象以适应iPad的不同方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个填充了行的表,每行包含图像,标题和按钮。

当用户更改iPad按钮的方向时,应根据iPad的方向重新排列。请告诉我如何在uitableview单元格中重新排列对象。

提前致谢。

I had a table populated with rows and each row contain image, title and a button.
When user change the orientation of the iPad button should be rearrange according to the orientation of iPad. Please advice me how to rearrange the object in uitableview cell.
Thanks in advance.

推荐答案

这将work:

-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

}

-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}  

现在实施以下方法:

-(void)checkOrientation
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
    {
        [tblView reloadData];
        // Set x coorinate of views you want to change

    }
    else
    {
        [tblView reloadData];
        // Set x coordinates of views to initial x xoordinates.

    }

}  

创建recievedRotate:

Create recievedRotate :

- (void)receivedRotate:(NSNotification *)notification
{    
[self checkOrientation];
}  

viewDidLoad 中:

-(void)viewDidLoad
{  
[self checkOrientation];
}

这篇关于在表格视图中重新排列对象以适应iPad的不同方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆