プログラマ行進曲第二章

主にソフトウェア関連の技術をネタにした記事を執筆するためのブログ

『iPhone SDKの教科書』学習日記 その2

今日も今日とて、大して書く事がないな〜なんて思いつつ、更新を致します。

本日は『iPhone SDKの教科書』を使ったiPhoneプログラミングの学習の第2回目です。

iPhone SDKの教科書―Cocoa Touchプログラミング、最初の一歩

iPhone SDKの教科書―Cocoa Touchプログラミング、最初の一歩

今回は前回と違い、ほとんど学習が進まず、p211からp226間でしか進みませんでした。しかもコンパイルエラーが出て、しかも原因が分からず立ち往生!

何がミスしているのか自分でもよくわかっていなく未だに原因不明なので、ここにソースコードでもコピペしてみて、明日冷静な頭になってから見直す事にしようと思います。

SmashViewController.h

#import <UIKit/UIKit.h>

@interface SmashViewController : UIViewController {
	IBOutlet UIButton *target; // 目標(UFO)
}

- (IBAction)smash; // UFOがタッチされた時
- (void)move:(NSTimer *)timer; // タイマーから呼び出される

@end

SmashViewController.m

#import "SmashViewController.h"

@implementation SmashViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
// ビューの読み込みが完了したときに呼び出されるメソッド
- (void)viewDidLoad {
    [super viewDidLoad];
	
	// 乱数の初期化
	srand(time(NULL));
	
	// タイマーの作成(動作開始)
	[NSTimer scheduledTimerWithTimeInterval:0.5 // 時間間隔(秒)
				         target:self // 呼び出すオブジェクト
				       selector:@selector(move:) // 呼び出すメソッド
                                       userInfo:nil // ユーザ利用の情報オブジェクト
                                        repeats:YES]; // 繰り返し
}

- (void)move:(NSTimer *)timer {
	// タイマー動作時の処理
	
	// UFOを移動
	int x = rand() % 320;
	int y = rand() % 480;
	target.center = CGPointMake(x, y);
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


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

@end

SmashViewController.mファイル内の

	[NSTimer scheduledTimerWithTimeInterval:0.5 // 時間間隔(秒)
				         target:self // 呼び出すオブジェクト
				       selector:@selector(move:) // 呼び出すメソッド
                                       userInfo:nil // ユーザ利用の情報オブジェクト
                                        repeats:YES]; // 繰り返し

のところ、より具体的には"@selector(move:)"のところでエラーが出ているんですよね。

まあ、クールダウンしたらエラー原因を解いてみて、進んでみようという感じです。