.NETからObjective-Cに移行するときに、コントロールとイベント処理の基本を学んでいます。
ARCとストーリーボードを使用して、XCode4.2でシングルビュープロジェクトを作成しました。ストーリーボードでは、ViewControllerに単一のUIImageViewとUIButtonがあります。UIImageViewには、IdentityInspectorの「label」エントリで「imgLock」という名前が割り当てられます。同じ手法を使用して、ボタンに「btnToggle」という名前を付けます。
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UIButton *btnToggle;
IBOutlet UIImageView *imgLock;
}
- (IBAction) toggleImage;
@property (readonly, strong) UIButton *btnToggle;
@property (readwrite, strong) UIImageView *imgLock;
@end
ViewController.m
#import "ViewController.h"
@implementation ViewController
@synthesize btnToggle, imgLock;
BOOL imgState;
- (void) toggleImage {
UIImage *img = [UIImage imageNamed: imgState ? @"Unlocked64" : @"Locked64"];
imgState = !imgState;
[imgLock setImage: img];
}
ストーリーボードで、ボタンから画像に青い線をCtrlキーを押しながらドラッグし、表示されるtoggleImage
コンテキストメニューから選択しました。
ブレークポイントを設定しtoggleImage
てプロジェクトをビルド/実行すると、imgLock
0x0を除いて、すべてが正常であることがわかります。私のWindowsの時代から、コントロールがそのまま「フォームに配置」されていたため、コントロールがインスタンス化されることを期待していたと思います。
プロセスを強制終了するときの警告を除いて、ログにはコメントがありません。警告:関数「void」の「/SourceCache/gdb/gdb-1708/src/gdb/macosx/macosx-nat-inferior.c」の2184行目のエラーmacosx_kill_inferior_safe() "