views:

87

answers:

1

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

A: 

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.

Randaltor
Received error: "UIWindow may not respond to -setnNeedsDisplay" and runtime error.
LoganFrederick
Theres an extra 'n' in that method call if that's not a typo. I did look at the API however and there is no parameter in the setNeedsDisplay message for UIWindow. try taking out the ":YES" part. That's from Mac Cocoa.
Randaltor