2014-02-07 21 views
1

旋转设备时,我的应用程序出现问题。 tableView扩展到设备视图,导致它无法访问。设备旋转时调整tableView的大小

我怎样才能得到表来调整因此这将不会发生呢?

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
     toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     NSLog(@"Device is rotated sidewise"); 

     myTable.delegate = self; 
     myTable.dataSource = self; 
     myTable.scrollEnabled = YES; 

     [self.view addSubview:myTable]; 

     myTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 148, 320, 10)]; 
    } 
} 

在编码xcode或objective-c时,我是一个完整的noob。我目前正在研究这个问题,所以请对你的答案保持友好。

+2

谷歌'autolayout'或' viewresizing masks'在iOS中 – Shubhank

回答

0

如果你需要做编程然后改变你的代码如下

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
     toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     NSLog(@"Device is rotated sidewise"); 
     myTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 148, 320, 10)]; 
     myTable.delegate = self; 
     myTable.dataSource = self; 
     myTable.scrollEnabled = YES; 

     [self.view addSubview:myTable]; 


    } 
} 
2

如果自动布局被关闭,然后你可以使用自动布局,如果你是通过界面生成器

添加的tableview autoresizemask应该看起来像这样

Autosizing masks needs to adjusted as per pic