2013-04-30 72 views
1

在我的應用程序中,我有一個表視圖。比方說,例如我在桌面視圖中有10行值得數據,頂部有一個導航欄。我以縱向模式啓動應用程序。我看到10行。XCode表視圖從肖像旋轉到風景隱藏第一行

現在我將iPad旋轉到橫向模式。我只看到9行。 1行隱藏在頂部導航工具欄下方。

我把它旋轉回肖像,但我仍然只能看到9行。 1行仍然隱藏在導航欄下方。我拖動表視圖並查看第一行。所以我的問題是,即使當我從肖像變爲風景時,我也會做出什麼變化才能看到所有10行,反之亦然。我試圖改變tableview的setFrame值,但沒有運氣。如果您需要更多信息,請詢問。謝謝。

+0

嘗試編輯您的問題,很難遵循。 – 2013-04-30 20:27:10

+0

@SpaceDust。我改變了它。這有幫助嗎? – RookieAppler 2013-04-30 20:35:46

+0

導航欄是來自導航控制器堆棧還是您只是將導航欄拖到視圖中? – 2013-04-30 20:44:26

回答

0

我沒有一個完整的答案給你,我不知道爲什麼你的第一行是在導航欄下面,也許你應該提供額外的代碼或屏幕截圖。

在最糟糕的情況下,我會做tableview分組,並安排-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section 或我會從界面生成器中的對象拖放到視圖上方的虛擬視圖,這種方式第一行不能在導航下酒吧。

總而言之,如果您必須在縱向和橫向上顯示所有行,您可以檢測方向更改並使行高變小或變大。

添加通知在viewWillAppear中功能

-(void)viewWillAppear:(BOOL)animated{ 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];} 

的方向變化通知此功能取決於方向

- (void)orientationChanged:(NSNotification *)notification{ 
    [self.tableview reloadData]; 
} 

更改行高度和收縮行時的方位改變

//row height 
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    //portrait mode view 
    return 40.0; //play with the value according to your needs 
} 
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
{ 
    //landscape view 
    return 30.0; //play with the value according to your needs 
} 

} 
+0

謝謝。但它沒有奏效。我的第一行仍然隱藏。 – RookieAppler 2013-04-30 22:06:55

+0

它適用於:UIEdgeInsets inset = UIEdgeInsetsMake(44,0,0,0); \t \t self.tableView.contentInset = inset;我的第一排不再隱藏。但有時候我會在頂部排空。但如果我在風景和肖像之間移動,它會消失,我可以看到所有10行。 – RookieAppler 2013-05-01 15:42:23

+0

我不知道爲什麼它發生它不應該,祝你好運:) – 2013-05-01 16:59:29