Black screen on iOS simulator


#1

Hello, I am working through chapter 6 and I have reached the point where we are supposed to set up a for-loop to draw the circles. As far as I can tell, I have typed the code in correctly but when I run it in the simulator all I see is a black screen. Why is this?

[code]//
// HypnosisterAppDelegate.h
// Hypnosister
//
// Created on 3/8/13.
// Copyright © 2013. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface HypnosisterAppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;

@end

[/code]

[code]//
// HypnosisterAppDelegate.m
// Hypnosister
//
// Created on 3/8/13.
// Copyright © 2013. All rights reserved.
//

#import “HypnosisterAppDelegate.h”
#import “HypnosisView.h”

@implementation HypnosisterAppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    HypnosisView *view = [[HypnosisView alloc] initWithFrame:[[self window]bounds]];
    [[self window] addSubview:view];

    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:.
    }

@end
[/code]

[code]//
// HypnosisView.h
// Hypnosister
//
// Created on 3/8/13.
// Copyright © 2013. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface HypnosisView : UIView

@end
[/code]

[code]//
// HypnosisView.m
// Hypnosister
//
// Created on 3/8/13.
// Copyright © 2013 All rights reserved.
//

#import “HypnosisView.h”

@implementation HypnosisView

  • (id)initWithFrame:(CGRect)frame
    {
    self = [super initWithFrame:frame];
    if (self) {
    [self setBackgroundColor:[UIColor clearColor]];
    }
    return self;

}

  • (void)drawRect:(CGRect)dirtyRect
    {
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect bounds = [self bounds];

    //figure out the center of the bounds rectangle
    CGPoint center;
    center.x = bounds.origin.x + bounds.size.width / 2.0;
    center.y = bounds.origin.y + bounds.size.height /2.0;

    // the radius of the circle should be nearly as big as the view
    float maxRadius = hypot(bounds.size.width, bounds.size.height) / 4.0;

    //the thickness of the line should be 10 points wide
    CGContextSetLineWidth(ctx, 10);

    //the color of the line should be gray (red/green/blue = 0.6, alpha = 1.0)
    CGContextSetRGBStrokeColor(ctx, 0.6, 0.6, 0.6, 1.0);

    //draw concentric circles from the outside in
    for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20) {
    CGContextAddArc(ctx, center.x, center.y, currentRadius, 0.0, M_PI * 2.0, YES);

      CGContextStrokePath(ctx);
    

    }

}

@end
[/code]