UISwitchの利用 – iPhoneアプリケーション開発
-
iPhoneらしいUI
- xcode起動
- 新規プロジェクト作成
- ViewBasedアプリケーション
- 名前入力
パーツ、UISwitchをつかってみる。
とりあえず、いつも通りview-basedアプリケーションを作る。
InterfaceBuilderファイルグループにある、[プロジェクト名]ViewController.xib(例:UISwitchViewController.xib)をダブルクリック。InterfaceBuilderを起動する。
View上に、SwitchとRound Rect Buttonを配置する。

xcodeに戻って、[プロジェクト名]Controller.h(例:UIViewController.h)を開き、IBOutletとしてUIButtonとUISwitchインスタンス変数を定義。また、対応するプロパティも定義し、ボタンクリック時のメソッドを作成。
UIViewController.h
#import <UIKit/UIKit.h>
@interface UISwitchViewController : UIViewController {
IBOutlet UIButton *uiButton;
IBOutlet UISwitch *uiSwitch;
}
@property(nonatomic, retain)UIButton *uiButton;
@property(nonatomic, retain)UISwitch *uiSwitch;
-(void)onClick:(id)sender;
@end
続いて、[プロジェクト名]Controller.m(例:UIViewController.m)を開き、プロパティの利用定義(@synthesize)とonClickメソッドを定義。
#import "UISwitchViewController.h"
@implementation UISwitchViewController
@synthesize uiButton;
@synthesize uiSwitch;
-(void)onClick:(id)sender{
if(uiSwitch.on == YES){
NSLog(@"YES!!!");
}else{
NSLog(@"NO!!!");
}
}
InterfaceBuilderを開き、IBOutletと変数、ボタンクリックとメソッドのひも付けを行う

とってもすてき。
PHP – mbstring拡張モジュールのインストール
CentOS5にPHPを標準インストールした環境を提供してもらい、確認してみたらmb_xxx系のメソッドが動かない!で、調べてみたら、mbstring拡張モジュールがはいってなかった。
その対策
yumでインストール
yum -install php-mbstring
あとは、php.iniを編集するだけ。超便利。
rpmでインストール
通常はyumインストールでいいのだけれど、ネットワーク使えない場合とかは、rpmパッケージインストールする。
rpm入手
RPM Search等で、RPMファイル入手。
インストール
サーバにファイルを置いて、以下のコマンド
#rpm -ivh php-mbstring-5.3.3-1.el5.remi.i386.rpm
確認
#ls /etc/php.d curl.ini fileinfo.ini json.ini ldap.ini mbstring.ini ←!!!! phar.ini zip.ini
phpinfo()でも確認
<?php phpinfo() ?>
ナイス!
iPhone SDK – イベントのつかいかた
初心者用。
クイックスタート
プロジェクト準備
アプリケーションの作成
Interface Builderの起動
Interface Builderファイル→EventViewController.xibをダブルクリック

RoundRectButtonを2つ置く(ドラッグ)、それぞれのボタンをダブルクリックして、ラベルを「+」「-」にした。で、保存(Command+S)

Xcodeにもどって実行してみる(Command+Enter)

すてき。
続いてUIとソースコードをひもづける。Classes→EventViewController.hにボタン用変数とイベントを追加
#import <UIKit/UIKit.h>
@interface EventViewController : UIViewController {
IBOutlet UIButton *addButton;
IBOutlet UIButton *subButton;
}
@property(nonatomic, retain)UIButton *addButton;
@property(nonatomic, retain)UIButton *subButton;
-(void)addEvent:(id)sender;
-(void)subEvent:(id)sender;
@end
Classes→EventViewController.mを開く。(.hファイルと.mファイルの切り替えは、Option+Command+↑)
#import "EventViewController.h"
@implementation EventViewController
@synthesize addButton;
@synthesize subButton;
-(void)addEvent:(id)sender{
NSLog(@"addEvent");
}
-(void)subEvent:(id)sender{
NSLog(@"subEvent");
}
- (void)dealloc {
[super dealloc];
}
UIと変数のマッピング
再びInterface Builderをひらく(XcodeのEventViewController.xibを開く)
File’s OwnerのOutlet欄に、作成した変数とイベントメソッドが追加されている。
Received Action欄に表示されている、それぞれのイベントメソッド右側の○の上でマウスダウンして、View上の対応するボタンまでドラッグする。
(下図参照)

実行
ボタンを押すと、デバッガコンソール(xcodeで、実行→コンソール)に文字列が出力される。
その他
・保存(Command+S)
・ビルド(Command+B)
・ビルドして実行(Command+Enter)
・.mと.hの切り替え(Option+Command+↑)








