(Xcode/iPhone)辞書アプリ制作、の勉強メモ。

ブログ

 

「フレームワーク」

UIKit

 

「クラス」

UIReferenceLibraryViewControllerクラス(辞書を表示するクラス)

UISearchBarクラス(検索フィールドを表示するクラス)

 

「ソースコード」

 – (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

{

    NSString *term = searchBar.text;

    UIReferenceLibraryViewController *controller = [[UIReferenceLibraryViewControlleralloc] initWithTerm:term];

    [selfpresentViewController:controller animated:YEScompletion:NULL];

    [searchBar resignFirstResponder];

}

・引数で受け取った「辞書で調べたい文字列」をterm変数に代入

・termを引数にしてUIReferenceLibraryViewControllerクラスのインスタンスを作成

・presentViewController:animated:completion:メソッドで画面の上にモーダルビューコントローラを表示

・サーチバーのresignFirstResponderメソッドを呼び出すことでキーボードを隠す