2011-06-12 43 views
0

我正在構建我的第一個基本選項卡,具有其中一個視圖的應用程序作爲將顯示視圖控制器的導航控制器。標題欄阻擋的TableView

我運行到一個問題,在該點處,用戶選擇從第一tableview中的類別作爲屏幕截圖所示:http://www.cl.ly/7YOF

當tableviewcontroller的另一個實例被加載並被推到navigationcontroller的堆疊 http://www.cl.ly/7ZRz

表格視圖選擇邏輯是以下:,該表由標題欄阻礙

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    KHCategory *selectedItem = [categoryArray objectAtIndex:indexPath.row]; 
    if (selectedItem.categories.count > 0) { 
     KHCategoryTableViewController *nextCategoryController = [[KHCategoryTableViewController alloc] init]; 
     nextCategoryController.categoryArray = [[NSArray alloc] initWithArray:selectedItem.categories]; 
     nextCategoryController.title = selectedItem.labelValue; 

     [self.navigationController pushViewController:nextCategoryController animated:YES]; 
     [nextCategoryController release]; 
    } else { 
     NSLog(@"show detail view"); 
    } 
} 

編輯: 我應該清楚,KHCategoryTableViewController的一個實例是我的NavigationController的根,NavController連線到TabController的第一個選項卡。

回答

0

,當我對着內置的iOS 4.3和iOS的不5.

0

檢查您的KHCategoryTableViewController視圖的autoResizingMask。在iPhone開發中心

UINavigationController的概述說:

注:由於篇幅 可用於自定義視圖的量可以改變 (取決於其他 導航視圖大小),自定義視圖的 autoresizingMask屬性應該是 設置爲具有靈活寬度和 高度。在顯示您的視圖之前, 導航控制器 會自動定位並調整它的大小以使其適合可用空間 。

+0

我添加[self.view setAutoresizingMask這個問題成爲解決: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];到KHCategoryTableViewController的viewDidLoad方法,但沒有幫助。我是否以錯誤的方式去做? – 2011-06-12 22:20:57

+0

我在手動和之後添加了蒙版之前輸出了蒙版的值,並且兩者的結果都是18.因此,UITableViewController視圖蒙版的默認值是18.感謝您的建議。 – 2011-06-13 00:29:03

4

兩個有趣的事情:它測量20個像素向下(狀態欄的大小)和您的行「nextCategoryController.title = ...」似乎並沒有做任何事情。所以...

1)我假設你還沒有使用setStatusBarHidden

2)看起來像navController的東西不工作。你能給出創建tabBar和NavController的appDelegate代碼嗎?

3)添加此代碼,並嘗試從您的子類別ViewDidLoad方法調用[self dumpWindow: @"VDL"]方法。每當檢查我的視圖結構是否正確時,我發現它非常寶貴。

- (void) dumpWindowFrom:(NSString *) fromText { 
    [self dumpViews: nil from:fromText]; 
} 

void dumpViewsRecursive(UIView* view, NSString *text, NSString *indent) { 
    Class cl = [view class]; 
    NSString *classDescription = [cl description]; 

    if ([text compare:@""] == NSOrderedSame) 
    NSLog(@"%d: %@ %@ %@", (int)view, classDescription, NSStringFromCGRect(view.frame), view.hidden ? @"Inv" : @"Vis"); 
else 
    NSLog(@"%d: %@ %@ %@ %@", (int)view, text, classDescription, NSStringFromCGRect(view.frame), view.hidden ? @"Inv" : @"Vis"); 

    for (NSUInteger i = 0; i < [view.subviews count]; i++) 
    { 
     UIView *subView = [view.subviews objectAtIndex:i]; 
     NSString *newIndent = [[NSString alloc] initWithFormat:@" %@", indent]; 
     NSString *msg = [[NSString alloc] initWithFormat:@"%@%d:", newIndent, i]; 
     dumpViewsRecursive (subView, msg, newIndent); 
     [msg release]; 
     [newIndent release]; 
    } 
}  

- (void) dumpViews: (UIView *) view { 
    dumpViewsRecursive (((!view) ? [[UIApplication sharedApplication] keyWindow] : view), @"" ,@""); 
} 

- (void) dumpViews: (UIView *) view from:(NSString *) fromText{ 
    dumpViewsRecursive ((!view) ? [[UIApplication sharedApplication] keyWindow] : view, fromText, @""); 
} 

4)你可以永遠只是欺騙並添加:

CGRect frame = [nextCategoryController.view frame]; 
frame.origin.y = frame.origin.y+20.0; 
[nextCategoryController.view setFrame:frame]; 
+0

感謝您提供詳細和深入的答案。幾天前我也嘗試過#4。然而,我昨晚得出了一個結論,我認爲我剛剛證實這是問題 - 我很愚蠢地針對iOS5 SDK進行構建。我今晚要做更多的測試,看看是否是這種情況。會讓你知道。 – 2011-06-15 14:37:27

+0

儘管你的答案並不是我的答案,但我會爲你提供良好的調試技巧和周到的答案,以獎勵你(明顯在7小時內)。 – 2011-06-15 15:45:18

+0

謝謝。我很驚訝5.0破壞了一些簡單的東西。 – mackworth 2011-06-15 15:55:01