2014-02-07 19 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