特にイベントハンドラの書き方、と言うか定義の仕方というか、紐付けの仕方が訳が分らなかったのでメモ。
あと、プロジェクト名が思いっきり typo ってたのでやり直し。
それと、シミュレータを起動した時に「プロセスにアタッチできません」等といったメッセージが出てしまうので、予め「システム環境設定」->「セキュリティとプライバシー」->「アクセシビリティ」に「Xcode」を追加しておくこと。
では、いってみよう。
「File」->「New」->「Project」をクリックし、プロジェクトを新規作成する。
「Choose a template for your new project」で「Single View Application」を選択し「Next」をクリック。

「Choose options for your new project」で「Product Name」等を設定し「Next」をクリック。

保存先を聞かれるので適当な場所を選択し「Create」をクリック。
この時「Source Control」にチェックを付け、「Create Git repository on」は「My Mac」にしておき、ローカルリポジトリを作成する。

「Project navigator」で「Main.storyboard」を選択する。

「Object library」から「Button」をドラッグし、「View」へドロップする。

「Attributes inspector」で「Title」の文字列を変更する。

ボタンを選択し「Align」をクリック、「Add new Alignment Constraints」の「Horizontally in Container」と「Vertically in Container」にチェックを付け、「Add 2 constraints」をクリックする。

「Resolve Auto Layout Issues」の「Updates Constraints」をクリックし、レイアウトを更新する。


「Show the Assistant editor」の「Assistant Editors on Bottom」をクリックする。


「Assistant Editor」の「Manual」を「Automatic」へ変更する。
これで表示中のオブジェクトのコードが自動的に表示される。


「Connections Inspector」を開き、「Sent Events」の「Touch Up Inside」右側の「○」をドラッグし、「Assistant Editor」に表示されているコード中の適当な場所へドロップする。
もしくは、ボタンオブジェクト上で右クリックしても同じ事が行える。

イベントの名前を入力し「Connect」をクリックする。
「ButtonExitTouchUpInside」とした。

イベントのコードに「exit(1)」を追加し、押されたらアプリを終了する様にする。
ここで、「File」->「Save」で保存。

「Set the active Scheme」で「iPhone 5s」を選択し、「Build and then run the current scheme」でシミュレータを実行。

「Exit」ボタンをタップすれば、アプリが終了し、ホーム画面が表示される。

「Source Control」->「Commit」で、編集したファイルにコメントを付け、ローカルリポジトリにコミットして終了。

とまあ、イベントハンドラの追加まではなんとか出来た。
イベントハンドラの追加の仕方が独特過ぎて、最初はかなり混乱したが、まさかのドラッグ & ドロップ…。
まあ、解ってしまえば簡単なんだが、けっして直感的じゃないよなぁ…。
0 件のコメント:
コメントを投稿