いきなりですが、Zaurusではなく、iPhoneアプリの開発の話です。
最近、iPhoneアプリの開発を仕事でやっているので、色々なサイトを参考にしながらUIViewControllerのテンプレートを作って備忘録として書いてみました。
本来であれば、参考サイトを書いておくべきなのでしょうが、今回は保留とさせてください。(すみません、めんどくさがり屋なだけです。)
色々と独断と偏見が入っています。とりあえず、自分でMacは持っていないので空で打ってみました。
なので、コンパイルが通るかどうか不明です。
//
// TemplateViewController.h
//
#import <UIKit/UIKit.h>
@interface TemplateViewController : UIViewController {
@private
UIView *outletView1_; //
UIView *allocView1_; //
NSObject *valueObject1_; //
NSObject *valueObject2_; //
}
@property(nonatomic,retain) IBOutlet UIView *outletView1; //
+ (id)templateViewControllerWithObject:(NSObject *)object;
- (id)initWithObject:(NSObject *)object;
- (void)publicMethodWithObject:(NSObject *)object;
- (IBAction)action1:(id)sender;
@end
//
// TemplateViewController.m
//
#import "TemplateViewController.h"
@interface TemplateViewController()
@property(nonatomic,retain) UIView *allocView1; //
@property(nonatomic,retain) NSObject *valueObject1; //
@property(nonatomic,retain) NSObject *valueObject2; //
@end
@interface TemplateViewController(Private)
- (void)privateMethodWithObject:(NSObject *)object;
@end
@implementation TemplateViewController
@synthesize outletView1 = outletView1_; //
@synthesize allocView1 = allocView1_; //
@synthesize valueObject1 = valueObject1_; //
@synthesize valueObject2 = valueObject2_; //
+ (id)templateViewControllerWithObject:(NSObject *)object {
NSLog(@"%s", __FUNCTION__);
return [[[self alloc] initWithObject:object] autorelease];
}
- (id)init {
NSLog(@"%s", __FUNCTION__);
return [self initWithObject:nil];
}
- (id)initWithObject:(NSObject *)object {
NSLog(@"%s", __FUNCTION__);
if(self = [super init]) {
[self setValueObject1:object];
[self setValueObject2:[[[NSObject alloc] init] autorelease]];
}
return self;
}
- (void)dealloc {
NSLog(@"%s", __FUNCTION__);
[self setOutletView1:nil];
[self setAllocView1:nil];
[self setValueObject1:nil];
[self setValueObject2:nil];
[super dealloc];
}
- (void)didReceiveMemoryWarning {
NSLog(@"%s", __FUNCTION__);
[super didReceiveMemoryWarning];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
NSLog(@"%s", __FUNCTION__);
switch(interfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
return YES;
default:
return NO;
}
}
- (void)viewDidLoad {
NSLog(@"%s", __FUNCTION__);
[super viewDidLoad];
UIView *view;
view = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
[[self view] addSubView:view];
[self setAllocView1:view];
}
- (void)viewDidUnload {
NSLog(@"%s", __FUNCTION__);
[self setOutletView1:nil];
[self setAllocView1:nil];
[super viewDidUnload];
}
- (void)viewWillAppear:(BOOL)animated {
NSLog(@"%s", __FUNCTION__);
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"%s", __FUNCTION__);
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
NSLog(@"%s", __FUNCTION__);
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
NSLog(@"%s", __FUNCTION__);
[super viewDidDisappear:animated];
}
- (void)publicMethodWithObject:(NSObject *)object {
[self setValueObject1:object];
[self setValueObject2:object];
}
- (IBAction)action1:(id)sender {
[self privateMethodWithObject:sender];
}
@end
@implementation TemplateViewController(Private)
- (void)privateMethodWithObject:(NSObject *)object {
[self setValueObject2:object];
}
@end