在子視圖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];
}
爲什麼視圖顯示爲全黑與工具欄的任何想法。
從內存管理的角度來看,你的代碼似乎很奇怪,你顯然不使用ARC。無論如何,你在哪裏定義了這個視圖的內容,或者至少是他們的背景顏色,這樣你就可以看到發生了什麼?並且設置框架也是必須的。實際上,這段代碼應該會產生'全黑的工具欄'。 – 2012-02-13 18:08:29
我曾嘗試刪除工具欄,但刪除後顯示全黑屏幕無視圖 – user1120133 2012-02-13 18:22:15
現在我確實爲兩個視圖設置了框架,但仍顯示黑色。這些視圖的內容存儲在個人UIViewcontrollers – user1120133 2012-02-13 18:26:11