<?xml version="1.0" encoding="UTF-8" ?>
<rss version="0.91">
  <channel>
    <title>初心者が進めるiphoneアプリ開発</title>
    <description>Macもiphoneすらもよく使ったことのない超初心者がお送りする、iphoneアプリの作り方の解説です。難しいことは抜きにしてとにかく動かしてみましょう。</description>
    <link>http://iphoneapp.gjpw.net/</link>
    <language>ja</language>
    <copyright>Copyright (C) NINJATOOLS ALL RIGHTS RESERVED.</copyright>

    <item>
      <title>時間を取得して計測に使う（NSDate）</title>
      <description>タイマーを設定して10ms単位でカウントアップしても、タイマーは正確に10msでメソッドの実行ができないので時間を測定するのには使えません。そこでストップウォッチみたいに細かい時間の取得をするには「NSDate」クラスを使って、起動開始の時間と停止の時間との差分を求める方法があります。&lt;br /&gt;
&lt;br /&gt;
ヘッダでタイマ、タイマスタート時間、タイムアウトで実行するメソッドを宣言します。&lt;br /&gt;
&lt;br /&gt;

&lt;pre class=&quot;c&quot;&gt;@interface TestViewController : UIViewController {
    NSTimer *timer1;    //タイマ
    NSDate *stdate;    //タイマスタートの時間
}

- (void)timedisplay:(NSTimer *)timer;    //タイムアウトで時間表示するメソッド

@end
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
タイマーを起動する際に、タイマーのスタート時間を取得しておきます。&lt;br /&gt;
&lt;br /&gt;

&lt;pre class=&quot;c&quot;&gt;//タイマー動作開始、0.01秒きざみに設定
timer1 =
[NSTimer
scheduledTimerWithTimeInterval:0.01
target:self 
selector:@selector(timedisplay:) 
userInfo:nil 
repeats:YES]; 

//スタート時間の取得
stdate=[NSDate date];
[stdate retain];
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
タイムアウト時に数値を表示させる処理を入れます。&lt;br /&gt;
ここで、「timeIntervalSinceDate」メソッドを利用することで、ある日時からある日時までの経過秒数を取得することが可能です。&lt;br /&gt;
&lt;br /&gt;

&lt;pre class=&quot;c&quot;&gt;- (void)timedisplay:(NSTimer *)timer
{
    NSDate *now=[NSDate date];    //現在の時間を取得
    
    //開始時間と現在時間の差分を、少数点以下2桁で表示
    timedisplay.text=
    [NSString stringWithFormat:@&quot;%.2f&quot;,[now timeIntervalSinceDate:stdate]];
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
これでタイマー起動中は少数点以下の数値がそれらしく動き、タイマーを停止すればタイマーを起動した時間から停止した時間までの差分が出ます。タイマーを停止した直後に結果を表示させます。&lt;br /&gt;
&lt;br /&gt;

&lt;pre class=&quot;c&quot;&gt;[timer1 invalidate];
NSDate *now=[NSDate date];
timedisplay.text=
[NSString stringWithFormat:@&quot;%.2f&quot;,[now timeIntervalSinceDate:stdate]];
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0134a.jpg&quot; /&gt;&lt;br /&gt;
実行結果&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E6%99%82%E9%96%93%E3%82%92%E5%8F%96%E5%BE%97%E3%81%97%E3%81%A6%E8%A8%88%E6%B8%AC%E3%81%AB%E4%BD%BF%E3%81%86%EF%BC%88nsdate%EF%BC%89</link> 
    </item>
    <item>
      <title>要素とキーを対で持つ変更不可配列（NSDictionary）</title>
      <description>NSDictionaryは要素とキーを対として保持する変更不可なオブジェクト配列クラスです。キーを手がかりに要素を取り出すことが可能です。ディクショナリを作成して、キーや要素を取り出す例です。&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//ディクショナリをメモリ保持で作成
NSDictionary *tel;
tel=[[NSDictionary dictionaryWithObjectsAndKeys:
@&quot;9999-2377-9877&quot;,@&quot;荒井&quot;,
@&quot;9999-7656-0098&quot;,@&quot;加藤&quot;,
@&quot;9999-7677-9908&quot;,@&quot;佐藤&quot;,
@&quot;9999-4432-6678&quot;,@&quot;田中&quot;,
@&quot;9999-2213-1244&quot;,@&quot;中村&quot;,nil]retain];

//要素数を得る
int count;
count=[tel count];
NSLog(@&quot;%d&quot;,count);
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0133a.jpg&quot; /&gt;&lt;br /&gt;
実行結果&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//キーから要素を得る
NSString *telStr;
telStr=[tel objectForKey:@&quot;田中&quot;];
NSLog(telStr);
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0133b.jpg&quot; /&gt;&lt;br /&gt;
実行結果&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//キーの配列を得る
NSArray *arrKeys;
arrKeys=[tel allKeys];

//コンソールに表示
for (NSString *element in arrKeys) {
    NSLog(element);
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0133c.jpg&quot; /&gt;&lt;br /&gt;
実行結果&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//要素の配列を得る
NSArray *arrValues;
arrValues=[tel allValues];

//コンソールに表示
for (NSString *element in arrValues) {
    NSLog(element);
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0133d.jpg&quot; /&gt;&lt;br /&gt;
実行結果&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
キーの配列と要素の配列のログから、配列として生成される順番はバラバラだけど、「Key」と「Value」の対はちゃんと一致していることが分かります。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E8%A6%81%E7%B4%A0%E3%81%A8%E3%82%AD%E3%83%BC%E3%82%92%E5%AF%BE%E3%81%A7%E6%8C%81%E3%81%A4%E5%A4%89%E6%9B%B4%E4%B8%8D%E5%8F%AF%E9%85%8D%E5%88%97%EF%BC%88nsdictionary%EF%BC%89</link> 
    </item>
    <item>
      <title>PickerViewの使い方（UIPickerView）</title>
      <description>PickerViewは自分で用意した複数の値の中から１つの値を選択してもらう時に使用します。値が選択されるとメソッドが起動して、選択された値を受け取ってそれに対する動作を決定します。&lt;br /&gt;
&lt;br /&gt;
「View-based Application」のフォーマットで作成したベースアプリを例に、実際に使用してみます。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://file.iphoneapp.gjpw.net/i0132a.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0132a.jpg&quot; width=&quot;500&quot; height=&quot;370&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
「Interface Builder」を起動し、メニューから「Tools」→「Library」を開きます。「Library - Cocoa Touch - Data Views」から「Picker View」をドラッグしてViewに置きます。Viewの横幅いっぱいで大きいですが、全体のサイズ変更はできないようです。上のラベルは動作確認用です。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ヘッダに&amp;lt;UIPickerViewDelegate&amp;gt;を書き加えてプロトコルの実装をしてください。&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;@interface AgeViewController : UIViewController
&amp;lt;UIPickerViewDelegate&amp;gt;{ //プロトコルの実装
    //アウトレット
    IBOutlet UILabel *display;        //ラベル
    IBOutlet UIPickerView *picker;    //ピッカービュー
}

@end
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://file.iphoneapp.gjpw.net/i0132b.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0132b.jpg&quot; width=&quot;500&quot; height=&quot;360&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
「Interface Builder」でアウトレットをラベル（動作確認用）とピッカービューに結び付けてください。黒いダイアログは「File's Owner」上で右クリック「control ＋ クリック」をすると出ます。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
アプリ起動直後、デリゲートを自分自身に設定します。&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;- (void)viewDidLoad {
    [super viewDidLoad];
    picker.delegate=self;    //デリゲートを自分自身に設定
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
サンプルとして、3列のピッカービューを定義します。1列目は1行、2列目は2行、3列目は3行のコンポーネントを設定します。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//列数の設定（設定する列の数をreturnで返す）
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}


//！！行も列も番号は0から始まるので注意
//列（componentの値で渡される）に対する、行数の設定（設定する行の数をreturnで返す）
- (NSInteger) pickerView: (UIPickerView*)pView
numberOfRowsInComponent:(NSInteger) component {
    if (component==0) {
        return 1;
    }
    else if(component==1){
        return 2;
    }
    else if(component==2){
        return 3;
    }
    else{
        return 0; //帰り値が存在するので、関係ない場合でもとりあえず0を返させる
    }
}


//列（componentの値）、行（rowの値）に対する表示するものを設定
- (NSString*)pickerView: (UIPickerView*)pView
titleForRow:(NSInteger) row forComponent:(NSInteger)component {
    if (component==0) {
        if(row==0){
            return [NSString stringWithFormat:@&quot;a&quot;];
        }
        else {
            return [NSString stringWithFormat:@&quot;0&quot;];
        }
    }
    else if (component==1) {
        if(row==0){
            return [NSString stringWithFormat:@&quot;1&quot;];
        }
        else if(row==1){
            return [NSString stringWithFormat:@&quot;2&quot;];
        }
        else {
            return [NSString stringWithFormat:@&quot;0&quot;];
        }
    }
    else if (component==2) {
        if(row==0){
            return [NSString stringWithFormat:@&quot;あ&quot;];
        }
        else if(row==1){
            return [NSString stringWithFormat:@&quot;い&quot;];
        }
        else if(row==2){
            return [NSString stringWithFormat:@&quot;う&quot;];
        }
        else {
            return [NSString stringWithFormat:@&quot;0&quot;];
        }
    }
    else {
        return [NSString stringWithFormat:@&quot;0&quot;];
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
ピッカービューの操作が起きたときにイベントを発生させるコードを書きます。このメソッドは、ピッカービューの項目の選択が確定した時に呼ばれます。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//選択されているindexを受け取って、ラベルに表示する
- (void) pickerView: (UIPickerView*)pView
didSelectRow:(NSInteger) row  inComponent:(NSInteger)component {
    int row1;
    int row2;
    int row3;
    
    row1 = [picker selectedRowInComponent:0];  //0列目が選択されているindex
    row2 = [picker selectedRowInComponent:1];  //1列目が選択されているindex
    row3 = [picker selectedRowInComponent:2];  //2列目が選択されているindex
    
    display.text=[NSString stringWithFormat:@&quot;%d - %d - %d&quot;,row1,row2,row3];
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0132c.jpg&quot; /&gt;&lt;br /&gt;
実行するとラベルにピッカービューで選択が確定した時の0～2列目のindex番号が表示されます。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/pickerview%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%EF%BC%88uipickerview%EF%BC%89</link> 
    </item>
    <item>
      <title>ナビゲーションバー（UINavigationController）にビューを追加する３</title>
      <description>空のページだと味気ないんで、ウェブページを表示してみます。&lt;br /&gt;
&lt;br /&gt;
「WebViewController.h」の編集&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;#import &lt;UIKit/UIKit.h&gt;

@interface WebViewController : UIViewController {
    //アウトレットの宣言
    IBOutlet UIWebView *wv;
}

//プロパティを宣言
@property (retain) UIWebView *wv;

@end
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
「WebViewController.m」の編集&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//プロパティを実装
@synthesize wv;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://file.iphoneapp.gjpw.net/i0121a.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0121a.jpg&quot; width=&quot;500&quot; height=&quot;357&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
「WebViewController.xib」を開き、「Library」から「View」へ「Web View」をドラッグ＆ドロップします。大きさは画面全体でいいです。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://file.iphoneapp.gjpw.net/i0121b.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0121b.jpg&quot; width=&quot;500&quot; height=&quot;236&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
「File's Owner」上で右クリック「control ＋ クリック」し、「wv」を「Web View」に紐付けします。保存して設定完了です。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
先ほどのソースの部分に、少し書き加えます。&lt;br /&gt;
&lt;br /&gt;
「RootViewController.m」の編集&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//テーブルがタップされたときの動作
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //クリックされたセルの名前を取得
    //ルートのテーブル名と比較
    NSString *name;
    name=[names objectAtIndex:indexPath.row];
    
    //クリックされたセルの名前に対するテーブル表示用
    NSArray *childNames=nil;    //子テーブルのセル文字列格納用
    if ([name isEqualToString:@&quot;東京都&quot;]) {
        childNames=[NSArray arrayWithObjects:@&quot;豊島区&quot;,@&quot;港区&quot;,nil];
    }
    else if ([name isEqualToString:@&quot;埼玉県&quot;]) {
        childNames=[NSArray arrayWithObjects:@&quot;さいたま市&quot;,@&quot;所沢市&quot;,@&quot;熊谷市&quot;,nil];
    }
    else if ([name isEqualToString:@&quot;千葉県&quot;]) {
        childNames=[NSArray arrayWithObjects:@&quot;柏市&quot;,@&quot;我孫子市&quot;,nil];
    }
    
    //childNamesの中身があれば実行（下の階層があれば移動する）
    //子のテーブルを作成して、アニメーションしながら移動する
    if (childNames) {
        //RootViewControllerのインスタンスを作成
        RootViewController *childViewController;
        childViewController=[[RootViewController alloc]
        initWithNibName:@&quot;RootViewController&quot; bundle:nil];
        [childViewController autorelease];
        
        //RootViewControllerの設定
        childViewController.title=name;
        childViewController.names=childNames;
        
        //RootViewControllerをコントローラスタックに追加
        [self.navigationController
        pushViewController:childViewController animated:YES];
    }
    else{
        //子の項目がクリックされた場合はこっちを通る
        //WebViewControllerのインスタンスを作成
        WebViewController *webView;
        webView=[[WebViewController alloc]
        initWithNibName:@&quot;WebViewController&quot; bundle:nil];
        [webView autorelease];
        
        //UIWebViewのインスタンスを作成
        webView.wv=[[UIWebView alloc]init];
        webView.wv.scalesPageToFit=NO;
        [webView.view addSubview:webView.wv];
        
        //ページを表示、「港区」ならグーグル、その他はヤフー
        NSString *urlStr;
        if ([name isEqualToString:@&quot;港区&quot;]) {
            urlStr=@&quot;http://www.google.co.jp/&quot;;
        }
        else {
            urlStr=@&quot;http://www.yahoo.co.jp/&quot;;
        }
        
        NSURL *url=[NSURL URLWithString:urlStr];
        NSURLRequest *req=[NSURLRequest requestWithURL:url];
        [webView.wv loadRequest:req];
        
        //WebViewControllerの設定
        webView.title=name;
        
        //WebViewControllerをコントローラスタックに追加
        [self.navigationController
        pushViewController:webView animated:YES];
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0121c.jpg&quot; /&gt;&lt;br /&gt;
「港区」だとグーグルへ、&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0121d.jpg&quot; /&gt;&lt;br /&gt;
「熊谷市」だとヤフーへ行きます。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E3%83%8A%E3%83%93%E3%82%B2%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%90%E3%83%BC%EF%BC%88uinavigationcontroller%EF%BC%89%E3%81%AB%E3%83%93%E3%83%A5%E3%83%BC%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B%EF%BC%93</link> 
    </item>
    <item>
      <title>ナビゲーションバー（UINavigationController）にビューを追加する２</title>
      <description>子のテーブルの項目がクリックされた場合、追加したビューにページが移るように組み込みます。&lt;br /&gt;
&lt;br /&gt;
「ナビゲーションバー（UINavigationController）の使い方２」のソース「RootViewController.m」の、タップされた時の動作に組み込みます。&lt;br /&gt;
&lt;br /&gt;
「RootViewController.m」の編集&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//ヘッダを追加します
#import &quot;WebViewController.h&quot;

//・・・・・略・・・・・

//テーブルがタップされたときの動作
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //クリックされたセルの名前を取得
    //ルートのテーブル名と比較
    NSString *name;
    name=[names objectAtIndex:indexPath.row];
    
    //クリックされたセルの名前に対するテーブル表示用
    NSArray *childNames=nil;    //子テーブルのセル文字列格納用
    if ([name isEqualToString:@&quot;東京都&quot;]) {
        childNames=[NSArray arrayWithObjects:@&quot;豊島区&quot;,@&quot;港区&quot;,nil];
    }
    else if ([name isEqualToString:@&quot;埼玉県&quot;]) {
        childNames=[NSArray arrayWithObjects:@&quot;さいたま市&quot;,@&quot;所沢市&quot;,@&quot;熊谷市&quot;,nil];
    }
    else if ([name isEqualToString:@&quot;千葉県&quot;]) {
        childNames=[NSArray arrayWithObjects:@&quot;柏市&quot;,@&quot;我孫子市&quot;,nil];
    }
    
    //childNamesの中身があれば実行（下の階層があれば移動する）
    //子のテーブルを作成して、アニメーションしながら移動する
    if (childNames) {
        //RootViewControllerのインスタンスを作成
        RootViewController *childViewController;
        childViewController=[[RootViewController alloc]
        initWithNibName:@&quot;RootViewController&quot; bundle:nil];
        [childViewController autorelease];
        
        //RootViewControllerの設定
        childViewController.title=name;
        childViewController.names=childNames;
        
        //RootViewControllerをコントローラスタックに追加
        [self.navigationController
        pushViewController:childViewController animated:YES];
    }
    else{
        //子の項目がクリックされた場合はこっちを通る
        //WebViewControllerのインスタンスを作成
        WebViewController *webView;
        webView=[[WebViewController alloc]
        initWithNibName:@&quot;WebViewController&quot; bundle:nil];
        [webView autorelease];
        
        //WebViewControllerの設定
        webView.title=name;
        
        //WebViewControllerをコントローラスタックに追加
        [self.navigationController
        pushViewController:webView animated:YES];
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0120a.jpg&quot; /&gt;&lt;br /&gt;
「豊島区」をクリックすると、「豊島区」という空のページへ移ります。ナビゲーションバーの「東京都」をクリックすると上のページへ戻ります。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E3%83%8A%E3%83%93%E3%82%B2%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%90%E3%83%BC%EF%BC%88uinavigationcontroller%EF%BC%89%E3%81%AB%E3%83%93%E3%83%A5%E3%83%BC%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B%EF%BC%92</link> 
    </item>
    <item>
      <title>ナビゲーションバー（UINavigationController）にビューを追加する１</title>
      <description>「Navigation-Based Application」のテンプレートでナビゲーションバーアプリケーションを作成すると、テーブルビューは用意されていてすぐに使用できますが、ほかのビューを表示するには追加してやる必要があります。まずはビューを追加します。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0119a.jpg&quot; /&gt;&lt;br /&gt;
「Classes」を右クリック「control ＋ クリック」して、「追加」→「新規ファイル...」とたどってクリックします。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://file.iphoneapp.gjpw.net/i0119b.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0119b.jpg&quot; width=&quot;500&quot; height=&quot;407&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
「UIViewController subclass」を選択し、オプションの「With XIB for user Interface」にチェックを入れて、「次へ」行きます。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://file.iphoneapp.gjpw.net/i0119c.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0119c.jpg&quot; width=&quot;500&quot; height=&quot;407&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
ファイル名をつけて「完了」で作成されます。「同時にヘッダも作成」にはチェックを入れたままにしてください。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0119d.jpg&quot; /&gt;&lt;br /&gt;
こんな感じに「h」「m」「xib」の3つのファイルができています。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0119e.jpg&quot; /&gt;&lt;br /&gt;
「xib」ファイルはドラッグ＆ドロップして「Resources」の中に移しておいてください。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://file.iphoneapp.gjpw.net/i0119f.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0119f.jpg&quot; width=&quot;500&quot; height=&quot;224&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
新しく作った「WebViewController.xib」を開き、「Library」から「View」をドラッグ＆ドロップしてください。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0119g.jpg&quot; /&gt;&lt;br /&gt;
「File's Owner」上で右クリックし、「view」を「View」に紐付けします。保存してビューの追加ができました。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E3%83%8A%E3%83%93%E3%82%B2%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%90%E3%83%BC%EF%BC%88uinavigationcontroller%EF%BC%89%E3%81%AB%E3%83%93%E3%83%A5%E3%83%BC%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B%EF%BC%91</link> 
    </item>
    <item>
      <title>アラートの表示（UIAlertView）</title>
      <description>アラートはユーザーに確認や注意を促したり、複数の選択肢から選択してもらって結果を得る場合に出す、ポップアップ画面です。&lt;br /&gt;
&lt;br /&gt;
◆ボタン1個の例&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;UIAlertView *alert=[[UIAlertView alloc]init];
alert.title=@&quot;完了確認&quot;;
alert.message=@&quot;設定しました&quot;;
[alert addButtonWithTitle:@&quot;了解&quot;];
[alert show];
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0131a.jpg&quot; /&gt;&lt;br /&gt;
実行結果&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
◆ボタン2個の例&lt;br /&gt;
&lt;br /&gt;
ボタンが2個になると、どちらが選択されたかを受け取る必要があります。そこでデリゲートを設定してメソッドを呼ぶように設定します。&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;UIAlertView *alert=[[UIAlertView alloc]init];
alert.delegate=self;  //Alertのボタンが押されるとメソッドが呼ばれる
alert.title=@&quot;内容確認&quot;;
alert.message=@&quot;この内容でよろしいでしょうか？&quot;;
[alert addButtonWithTitle:@&quot;いいえ&quot;];
[alert addButtonWithTitle:@&quot;はい&quot;];
[alert show];
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//呼ばれるメソッド
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex{

    UIAlertView *alert2=[[UIAlertView alloc]init];
    alert2.title=@&quot;完了確認&quot;;
    
    if (buttonIndex==0) {
        alert2.message=@&quot;取り消しました&quot;;
        [alert2 addButtonWithTitle:@&quot;了解&quot;];
        [alert2 show];
    }
    else if (buttonIndex==1) {
        alert2.message=@&quot;設定しました&quot;;
        [alert2 addButtonWithTitle:@&quot;了解&quot;];
        [alert2 show];
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0131b.jpg&quot; /&gt;&lt;br /&gt;
「いいえ」か「はい」かを選択&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0131c.jpg&quot; /&gt;&lt;br /&gt;
「いいえ」の場合&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0131d.jpg&quot; /&gt;&lt;br /&gt;
「はい」の場合&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0131e.jpg&quot; /&gt;&lt;br /&gt;
（おまけ）ボタンが3つの場合&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/%E3%82%A2%E3%83%A9%E3%83%BC%E3%83%88%E3%81%AE%E8%A1%A8%E7%A4%BA%EF%BC%88uialertview%EF%BC%89</link> 
    </item>
    <item>
      <title>Text Fieldの使い方３（UITextField）</title>
      <description>入力に使用するキーボードのスタイルも変更することができます。&lt;br /&gt;
&lt;br /&gt;
◆keyboardType（キーボードのスタイル）&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130a.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.keyboardType=UIKeyboardTypeDefault;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130b.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.keyboardType=UIKeyboardTypeASCIICapable;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130c.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130d.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.keyboardType=UIKeyboardTypeURL;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130e.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.keyboardType=UIKeyboardTypeEmailAddress;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130f.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.keyboardType=UIKeyboardTypeNumberPad;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130g.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.keyboardType=UIKeyboardTypePhonePad;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
※UITextFieldで日本語のキーボードを出す設定は無いですが、キーボードタイプにデフォルトを設定すると、実機において前回使っていたキーボードが出ます。日本語キーボードを出したい場合には「UIKeyboardTypeDefault」に設定しておいてください。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
◆returnKeyType（キーボードの「return」キー）&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130h.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyDefault;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130i.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyGo;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130j.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyGoogle;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130k.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyJoin;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130l.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyNext;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130m.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyRoute;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130n.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeySearch;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130o.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeySend;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130p.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyYahoo;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130q.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyDone;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0130r.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.returnKeyType=UIReturnKeyEmergencyCall;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/text%20field%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%EF%BC%93%EF%BC%88uitextfield%EF%BC%89</link> 
    </item>
    <item>
      <title>Text Fieldの使い方２（UITextField）</title>
      <description>UITextFieldのプロパティを変更することによってスタイルなどを変えることができます。&lt;br /&gt;
&lt;br /&gt;
◆text&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129a.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.text=@&quot;テキスト&quot;;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
◆textColor&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129b.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.text=@&quot;赤テキスト&quot;;
tf.textColor=[UIColor redColor];
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
◆borderStyle&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129c.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.borderStyle=UITextBorderStyleRoundedRect;
tf.text=@&quot;UITextBorderStyleRoundedRect&quot;;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129d.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.borderStyle=UITextBorderStyleLine;
tf.text=@&quot;UITextBorderStyleLine&quot;;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129e.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.borderStyle=UITextBorderStyleBezel;
tf.text=@&quot;UITextBorderStyleBezel&quot;;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129f.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.borderStyle=UITextBorderStyleNone;
tf.text=@&quot;UITextBorderStyleNone&quot;;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
◆textAlignment&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129g.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.textAlignment=UITextAlignmentLeft;
tf.text=@&quot;左寄せ&quot;;  //デフォルト
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129h.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.textAlignment=UITextAlignmentRight;
tf.text=@&quot;右寄せ&quot;;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129i.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.textAlignment=UITextAlignmentCenter;
tf.text=@&quot;中央寄せ&quot;;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
◆placeholder（入力の説明文）&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0129j.jpg&quot; /&gt;&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;tf.placeholder=@&quot;登録するサイト名を入力してください&quot;;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/text%20field%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%EF%BC%92%EF%BC%88uitextfield%EF%BC%89</link> 
    </item>
    <item>
      <title>Text Fieldの使い方１（UITextField）</title>
      <description>「Text Field」とはユーザーからの入力を受け取る場合に使用します。「Text Field」がタップされるとユーザーが入力するためのキーボードが出て、キーボードの「return」がタップされるとキーボードが引っ込むものを作ってみます。&lt;br /&gt;
&lt;br /&gt;
「TestViewController.h」の編集&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;@interface Test2ViewController : UIViewController {
    //アウトレットを追加
    IBOutlet UITextField *tf;
}

@end
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
「TestViewController.m」の編集&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;c&quot;&gt;//UITextFieldのデリゲートメソッドを追加
//イベントが発生した場合に呼ばれます

//テキストフィールドを編集する直前に呼び出されます
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    NSLog(@&quot;textFieldShouldBeginEditing&quot;);
    return YES;  //これをNOにすると、キーボードが出ません
}


//テキストフィールドを編集する直後に呼び出されます
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    NSLog(@&quot;textFieldDidBeginEditing&quot;);
}


//Returnボタンがタップされた時に呼び出されます
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSString *retStr;
    retStr=tf.text;  //テキストを受け取って
    NSLog(retStr);  //コンソールに表示
    
    //「resignFirstResponder」はユーザーのアクションに対して
    //最初に応答するオブジェクトを放棄するという命令なので
    //「tf」が放棄されて、キーボードも消えます
    [tf resignFirstResponder];
    return YES;
}


//テキストフィールドの編集が終了する直前に呼び出されます
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    NSLog(@&quot;textFieldShouldEndEditing&quot;);
    return YES;  //これをNOにすると、キーボードが消えません
}


//テキストフィールドの編集が終了する直後に呼び出されます
- (void)textFieldDidEndEditing:(UITextField *)textField{
    NSLog(@&quot;textFieldDidEndEditing&quot;);
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
「TestViewController.xib」の編集&lt;br /&gt;
&lt;br /&gt;
「Resources」から「TestViewController.xib」をダブルクリックして「Interface Builder」を開きます。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://file.iphoneapp.gjpw.net/i0128a.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0128a.jpg&quot; width=&quot;500&quot; height=&quot;333&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
「Library」から「Text Field」を「View」にドラッグ＆ドロップします。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0128b.jpg&quot; /&gt;&lt;br /&gt;
「File's Owner」上で右クリック「control ＋ クリック」して、黒いダイアログを出し、「tf」と「Text Field」を紐付けします。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0128c.jpg&quot; /&gt;&lt;br /&gt;
「Text Field」上で右クリックして、黒いダイアログを出し、「delegate」と「File's Owner」を紐付けして保存します。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0128d.jpg&quot; /&gt;&lt;br /&gt;
実行して「Text Field」をタップするとキーボードが出て入力でき、「return」をタップすると入力を終了します。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://file.iphoneapp.gjpw.net/i0128e.jpg&quot; /&gt;&lt;br /&gt;
コンソールにはこのようなログが残ります。編集開始メソッド呼び出し後、「Text Field」に入力した内容を受け取ってログに残し、編集終了メソッドが呼ばれています。&lt;br /&gt;
&lt;br /&gt;
「textFieldShouldBeginEditing」や「textFieldShouldEndEditing」で「return NO;」にすると次のメソッドが呼ばれないので、動作を自由にエディットすることができます。（例：入力するのにキーボードの代わりにPicker Viewを出す）&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description> 
      <link>http://iphoneapp.gjpw.net/%E6%9C%AA%E9%81%B8%E6%8A%9E/text%20field%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%EF%BC%91%EF%BC%88uitextfield%EF%BC%89</link> 
    </item>

  </channel>
</rss>