0
我正在學習iPhone上的Objective-C如何將視圖層疊到主窗口上。iPhone在Windows上添加視圖練習
我已經嘗試重新制作一個基本程序,以在應用程序的主UIView上繪製兩個不同的彩色矩形視圖,但似乎不起作用。
我目前的輸出是一個白色的屏幕。 但是,當我關閉應用程序時,它會在關閉時簡要顯示兩個矩形,這使我相信它們已被繪製,但由於某些原因而未顯示。
假設下面的psuedo代碼(爲了StackOverflow而縮短了原始文檔,但直接複製到了我的項目中)沒有問題,我還需要做些什麼才能讓我的項目顯示這些矩形?
從蘋果代碼在我TestAppDelegate.m文件:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Create the window object and assign it to the
// window instance variable of the application delegate.
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.backgroundColor = [UIColor whiteColor];
// Create and initialize a simple red square
// Create and initializesimple blue square
// Add the square views to the window
[window addSubview:redView];
[window addSubview:blueView];
// Once added to the window, release the views to avoid the
// extra retain count on each of them.
[redView release];
[blueView release];
// Show the window.
[window makeKeyAndVisible];
}
鏈接到原始蘋果文檔:http://tinyurl.com/y8alvgt
收到錯誤:「UIWindow可能不會響應-setnNeedsDisplay」和運行時錯誤。 – LoganFrederick 2009-11-06 21:45:59
如果這不是打字錯誤,那麼在該方法中額外打上'n'。 但是我看過API,並且UIWindow的setNeedsDisplay消息中沒有參數。嘗試取出「:是」部分。這來自Mac Cocoa。 – Randaltor 2009-11-06 22:14:44