Only get blank white screen


#1

I put in all the code as the book says for the fitst part (It is supposed to generate the lightGreyColor concentric circles)
I only get a white screen when I build and run. There are no warnings or issues.

Any suggestions?

HypnosisAppDelegate.h

//
//  HypnosisterAppDelegate.h
//  Hypnosister
//
//  Created by Gazelle on 6/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
@class HypnosisView;

@interface HypnosisterAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    HypnosisView *view;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

HypnosisAppdelegate.m

//
//  HypnosisterAppDelegate.m
//  Hypnosister
//
//  Created by Gazelle on 6/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "HypnosisterAppDelegate.h"
#import "HypnosisView.h"

@implementation HypnosisterAppDelegate


@synthesize window=_window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    CGRect wholeWindow = [window bounds];
    view = [[HypnosisView alloc] initWithFrame:wholeWindow];
    [view setBackgroundColor:[UIColor clearColor]];
    [window addSubview:view];

    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
     */
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

- (void)dealloc
{
    [view release];
    [_window release];
    [super dealloc];
}

@end

HypnosisView.h


//
//  HypnosisView.h
//  Hypnosister
//
//  Created by Gazelle on 6/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface HypnosisView : UIView {
    
}

@end

MypnosisView.m


//
//  HypnosisView.m
//  Hypnosister
//
//  Created by Gazelle on 6/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "HypnosisView.h"


@implementation HypnosisView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    CGRect bounds = [self bounds];
    CGPoint center;
    center.x = bounds.origin.x + bounds.size.width /2.0;
    center.y = bounds.origin.y + bounds.size.height /2.0;
    float maxRadius = hypot(bounds.size.width, bounds.size.height);
    CGContextRef context = UIGraphicsGetCurrentContext()   ;
    CGContextSetLineWidth(context, 10);
    [[UIColor   lightGrayColor] setStroke];
    for (float currentRadius = maxRadius; currentRadius >0; currentRadius -=20)
    {
        CGContextAddArc(context, center.x, center.y, currentRadius, 0.0, M_PI * 2.0, YES);
        CGContextStrokePath(context);
    }
}


- (void)dealloc
{
    [super dealloc];
}

@end

#2

Answer here for anyone with same problem

viewtopic.php?f=48&t=650


#3

For what it’s worth, I was only getting a blank screen but the problem ended up being that I entered this:

CGRect wholeWindow = [window bounds]; 
[[HypnosisView alloc] initWithFrame:wholeWindow];
[view setBackgroundColor:[UIColor clearColor]]; 
[window addSubview:view];

Instead of this:

CGRect wholeWindow = [window bounds]; 
view = [[HypnosisView alloc] initWithFrame:wholeWindow]; 
[view setBackgroundColor:[UIColor clearColor]]; 
[window addSubview:view];

In case it’s not clear, I created my HypnosisView but then forgot to assign it to my instance variable, so it was lost and I was adding a nil subview to the window instead.


#4

BTW: You are missing / 2.0 on the following line

float maxRadius = hypot(bounds.size.width, bounds.size.height) [color=#FF0000]/ 2.0[/color];