2012-02-13 16 views
0

在子視圖UIView的等級時,則執行該操作會顯示全黑畫面視圖工具欄與不顯示的子視圖

- (void)displayviewsAction:(id)sender 
{ 

self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease]; 

self.view.frame = CGRectMake(0, 0, 320, 480); 

[self.view addSubview:toolbar]; 

UIView *viewController = [[UIView alloc] init]; 

UIView *secondController = [[UIView alloc] init]; 

[self.view insertSubview:viewController atIndex:1]; 

[self.view insertSubview:secondController atIndex:2]; 

NSLog(@"%d", [[self.view subviews] indexOfObject:viewController]); // Is 1 

NSLog(@"%d", [[self.view subviews] indexOfObject:secondController]); // Is 2 

[self.view bringSubviewToFront:viewController]; 

NSLog(@"%d", [[self.view subviews] indexOfObject:viewController]); 

[self.view sendSubviewToBack:viewController]; 

NSLog(@"%d", [[self.view subviews] indexOfObject:viewController]); 

[self.view bringSubviewToFront:secondController]; 

NSLog(@"%d", [[self.view subviews] indexOfObject:secondController]); 

SecondViewController * secondController = [[[SecondViewController alloc] init]autorelease]; 

secondController.view.frame = CGRectMake(0, 0, 320, 480); 

[self.view addSubview:secondController.view]; 

[self.view addSubview:toolbar]; 

} 

爲什麼視圖顯示爲全黑與工具欄的任何想法。

+0

從內存管理的角度來看,你的代碼似乎很奇怪,你顯然不使用ARC。無論如何,你在哪裏定義了這個視圖的內容,或者至少是他們的背景顏色,這樣你就可以看到發生了什麼?並且設置框架也是必須的。實際上,這段代碼應該會產生'全黑的工具欄'。 – 2012-02-13 18:08:29

+0

我曾嘗試刪除工具欄,但刪除後顯示全黑屏幕無視圖 – user1120133 2012-02-13 18:22:15

+0

現在我確實爲兩個視圖設置了框架,但仍顯示黑色。這些視圖的內容存儲在個人UIViewcontrollers – user1120133 2012-02-13 18:26:11

回答

2

視圖的默認背景色爲零,這是一個透明的背景。

如果您在任何視圖中沒有任何內容並且沒有爲它們設置任何背景顏色,則窗口或設備的默認背景將顯示出來。我沒有在文檔中看到它,但我認爲它是黑色的。

此外,您已定義UIView指針,但用「控制器」這個詞來命名它們。這可能會導致錯誤,因爲UIViewController是完全不同的對象。 UIViewController包含一個UIView並與它交互,但它不是UIView,也不是從一個UIView繼承而來。

+0

在視圖中我有uiimage和uitext,加上視圖的backgroundcolor – user1120133 2012-02-13 18:20:07