前へ | Xcc>Cocoa | 次へ |
ということで、まずは NSButton を調べる。Webブラウザの要領でクリックすれば NSButton が表示されるざんす。 NSButton にも見つからず NSControl でようやく見つかる。
こんな感じで書かれています。
これが MyPopUpButton.h に書き込むべき文章。 setIntValue もありますな。
というわけで、さっそく MyPopUpButton.h に書き込み〜
intValue も setIntValue も最後に";"がついてるけど、これは決まり。 MyPopUpButton.mも同様に
こっちは";"のかわりに{}です。で、この{}の中に新しい処理を書いていくことになる。 |
- (int)intValue- インスタンス用 APIかクラス用 API を識別するのに用いられる。 (int) このAPIはint型を返しますという意味。 int型自然数。小数点はあらわせない。- (void) setIntValue: (int) anInt(void) このAPIはなにも返しませんという意味。 (int)anInt この API は追加情報として int 型の値が必要ですという意味。 ";"がついてるセミコロンと呼ぶ。ひとつの命令が終わったよいう合図。 |
ここでMyPopUpButtonでやりたいことを整理すると
intValue
setIntValue
というとになる。これにもとづいて、さっきの辞書で NSPopUpButton を調べると選択されている項目の文字列を得るには titleOfSelectedItemReturns the title of the item last selected by the user.- (NSString *)titleOfSelectedItem なんてのがあったので、これを使うことにする。 |
メニュー項目を選ぶには
selectItemWithTitleSelects the item with the specified title. - (void)selectItemWithTitle:(NSString *)title が使えそう。で最終的に書き込まれたのがこれ。
保存して、Xcodeに戻って実行〜。 |
anInt = (anInt / 10) * 10;数学の表記だと=は同一という意味だが、コンピュータ言語だと代入の意味になる。anIntを10で割って、10をかけた値をanIntに代入している。int型は小数点を持てないので例えばanIntが36だとすると36/10は3.6だが小数点は無視され3となる。これに10をかけるのでanIntは30となる。メニューが0、10、20、...、50ととびとびなので、この演算を入れている。しかし項目のない60以降はどうなるのかというと... NSStringanInt を文字列にしている。 |