0

XCODE 4.5.2 からシングル ビュー アプリケーション テンプレートを選択しました。UIView クラス Graphics の型を作成した RDViewController.xib を持つビューコントローラーである appdelegate があります。また、Graphics.h と Graphics.m (drawRect メソッド) があります。タイプGraphicsクラスのviewController.mにgraphicsプロパティがあります。drawRect メソッドを実行すると呼び出されますが、シミュレーターには何も描画されません。Graphics クラスの initWithFrame メソッドが呼び出されていません。RDViewController.xib は Graphics のサブクラスになります。

appdelegate で:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[RDViewController alloc] initWithNibName:@"RDViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

私が書いた唯一のViewControllerで:

@implementation RDViewController

@synthesize graphics;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self.graphics setNeedsDisplay];
}

UIView サブクラス Graphics で

@implementation GraphicsView

- (id)initWithFrame:(CGRect)frame
{
    NSLog(@"Frame: %@", NSStringFromCGRect(frame));
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    UIFont *helveticaBold;

    [UIFont fontWithName:@"HelveticaNeue-Bold" size:40.0f];

    NSString *myString = @"Test string function";

    [myString drawInRect:CGRectMake(20.0f,20.0f,40.0f,160.0f)
                withFont:helveticaBold];

    self.backgroundColor = [UIColor whiteColor];
}

drawRect メソッドを実行すると呼び出されますが、シミュレーターには何も描画されません。Graphics クラスの initWithFrame メソッドが呼び出されていません。RDViewController.xib は Graphics のサブクラスになります。

4

2 に答える 2