开发者

iPhone Adding Views on Windows Practice

I'm learning how Objective-C on the iPhone layers views onto the main window.

I've tried remaking a basic program to draw two different colored rectangular views onto the main UIView for an app, but it does not seem to work.

My current output is a white screen. However, when I close the application, it briefly shows the two rectangles as they're closing, making me believe they're drawn but not displayed for some reason.

Assuming the psuedo-code below (shortened from the original documentation for the sake of StackOverflow, but copied directly into my project) is fine, what开发者_如何学运维 else might I have to do to my project to get these rectangles to display?

Code from Apple in my TestAppDelegate.m file:

 - (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];
}

Link to Original in Apple Docs: http://tinyurl.com/y8alvgt


You may need to call setNeedsDisplay on the window

[window setNeedsDisplay];

this has the effect of telling CocoaTouch that your window contents have changed and need to be redrawn.

Here's a link to the documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜