Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome or Safari browser. Firefox 10 (to be released soon) will also handle it.

はじめてのXcodeとiPhoneアプリ開発

@ton1517

自己紹介

tonです

URL

このスライドやサンプルコードなどはgithubにあります

https://github.com/ton1517/kohanet-iPhoneApp-study

目次

  1. アンケート
  2. Xcode Tutorial
  3. Storyboard and UIKit Tutorial
  4. Objective-C Tutorial
  5. Develop iPhone App!

1 アンケート

2 Xcode Tutorial

さっそくXcodeを起動しましょう。

*tutorialブランチに途中のサンプルコードが入ってます

まず...

Preferences -> Downloads

シミュレータとドキュメントはインストールしてますか?

プロジェクト作成

Single View Application で作成

とりあえず実行

シミュレータ起動

シミュレータの使い方

Xcodeのパネル

デバッグ

他は逐次説明します

3 Storyboard, UIKit Tutorial

Autolayout

この機能がオンになっているとiOS5で起動した時落ちる

今回はオフに

Initial View Controller

初期画面

UIKit

iPhoneアプリケーション・UIに関するフレームワーク

MVCを理解しているとわかりやすい

UIKitの基本的なView

適当に配置してみましょう * UIView * UIButton * UILabel * UITextField * etc...

UIViewController

Viewを管理するヤツ

基本的に1画面1ViewController

画面の遷移

画面を遷移する方法は複数ある

StoryBoard上の部品とコードの紐付け

UIViewControllerを継承したクラスを作り、 StoryBoardからドラッグで紐付ける

ViewControllerライフサイクル

生成、表示、破棄などのタイミングでメソッドが呼ばれる

適切な場所に処理を書く必要がある

4 Objective-C Tutorial

Objective-C

C言語にオブジェクト指向を加えた言語

C言語の上位互換なので素のC言語を書くこともできる

変数

C言語と一緒

int a = 1;
double b = 3.14;

真偽値はYES, NO

BOOL flag = YES;

ポインタ

NSString *str;

制御文 if

if ( a ) {

} else if ( b ) {

} else {

}

制御文 for

for (int i = 0; i < length; i++) {

}

文字列

NSString *str = @"hogehoge";

数値

NSNumber *num = @10.00;

配列

NSArray *array = @[@"a", @"b", @"c"];
NSLog(@"%@", array[1]);
NSLog(@"個数 %@", [array count]);

辞書

NSDictionary *dict = @{@"a" : @1, @"b" : @2};
NSLog(@"%@", dict[@"a"]);

クラス宣言

@interface ClassName : SuperClassName

@end

クラス実装

@implementation ClassName

@end

関数

宣言

- (void) hello:(NSString *)name;

実装

- (void) hello :(NSString *)name {
    NSLog(@"hello %@", name);
}

呼び出し

[self hello:@"world"];

プロパティ

getter/setter

宣言

@property(nonatomic) NSString *name;

宣言のみの場合以下のようなコードが自動生成される

実装

- (NSString *)name {
    return _name;
}
- (void)setName:(NSString *)name {
    _name = name;
}

カテゴリ

既存のクラスに自分で実装したメソッドを追加出来る機能

プロトコル

JavaやAS3でいうインターフェース

5 Develop iPhone App!

iPhoneアプリ作成

KohanetのWebページを表示するアプリを作りましょう

一緒に手を動かしていきます

*appブランチにプロジェクトがあります 途中経過はコミットを辿ってください

icon

GLYPHICONS

付録 - チェックサイト

付録 - 便利なツール

おわり

Use a spacebar or arrow keys to navigate