More Related Content Similar to UIViewControllerのコーナーケース Similar to UIViewControllerのコーナーケース (20) UIViewControllerのコーナーケース2. iPhone SDK
• touch •MyWebClip
•LDR touch •
• • on the WEB
•LCD Clock •i-Radio
•Subway Map •
13. iPhone SDK
#import <UIKit/UIKit.h>
#import "MyLabel.h"
#import "MyButton.h"
@interface SecondViewController : UIViewController {
MyLabel *label;
MyButton *button;
}
@property (nonatomic, retain) IBOutlet MyLabel *label;
@property (nonatomic, retain) IBOutlet MyButto *button;
- (IBAction)buttonPushed:(id)sender;
@end
16. iPhone SDK
#import <UIKit/UIKit.h>
#import "MyLabel.h"
#import "MyButton.h"
@interface SecondViewController : UIViewController {
IBOutlet MyLabel *label;
IBOutlet MyButton *button;
}
- (IBAction)buttonPushed:(id)sender;
@end
25. iPhone SDK
#import <UIKit/UIKit.h>
#import "MyLabel.h"
#import "MyButton.h"
@interface SecondViewController : UIViewController {
MyLabel *label;
MyButton *button;
}
@property (nonatomic, retain) MyLabel *label;
@property (nonatomic, retain) MyButton *button;
- (void)buttonPushed:(id)sender;
@end
31. iPhone SDK
@interface SecondViewController() {
MyLabel *label;
MyButton *button;
}
@property (nonatomic, retain) MyLabel *label;
@property (nonatomic, retain) MyButto *button;
@end
@implementation SecondViewController
...
34. iPhone SDK
nib nib
(Mac OS X iPhone )
Objective-C
@property (attributes) IBOutlet UserInterfaceElementClass *anOutlet;
Cocoa
35. iPhone SDK
( Mac OS X (44
) iPhone (45 ) )
■
Mac OS X
@property (assign) IBOutlet UserInterfaceElementClass *anOutlet;
■
iPhone OS X
@property (nonatomic, retain) Outlet UIUserInterfaceElementClass *anOutlet;
(iPhone OS )dealloc
Cocoa
36. iPhone SDK
nib 1
UIKit setValue:forKey:
setter
setter
( (43 )
)
loadNibNamed:owner:options:
Cocoa
37. iPhone SDK
nib 1
UIKit setValue:forKey:
setter
setter
( (43 )
)
loadNibNamed:owner:options:
Cocoa
38. iPhone SDK
View Controller (didReceiveMemoryWarning)
1 View Controller
(didReceiveMemoryWarning UIViewController
[self setView:nil] )
nib ( (43
) )
didReceiveMemoryWarning
Cocoa
39. iPhone SDK
View Controller
setView:
- (void)setView:(UIView *)aView {
if (!aView) { // nil
// nil
self.anOutlet = nil;
}
//
[super setView:aView];
}
UIViewController (
)setView: dealloc
dealloc self.anOutlet = nil
View Controller dealloc
Cocoa
41. + (void)initialize {
sectionIndexTitles =
iPhone SDK
[[NSArray arrayWithObjects:@"1-10", @"11-100", @"101-400", nil] retain];
}
- (id)init {
if (self = [super init]) {
self.pageURL = @"http://www.yahoo.co.jp";
operationQueue = [[NSOperationQueue alloc] init];
[operationQueue setMaxConcurrentOperationCount:1];
[NSFetchedResultsController deleteCacheWithName:nil];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
self.pageURL = nil;
[operationQueue release];
[super dealloc];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
42. - (void)loadView {
UIView *contentView =
[[UIView alloc] initWithFrame:
iPhone SDK
CGRectMake(0.0f, 0.0f, 320.0f, 367.0f)];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
[contentView release];
UIImageView *background =
[[UIImageView alloc] initWithImage:[UIImage
imageNamed:@"search_bg.png"]];
[contentView addSubview:background];
[background release];
searchBar = [[UISearchBar alloc] initWithFrame:
CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
searchBar.delegate = self;
searchBar.showsScopeBar = YES;
[[searchBar.subviews objectAtIndex:0]
performSelector:@selector(setBackgroundImage:)
withObject:[UIImage imageNamed:@"searchbar_bg.png"]];
[contentView addSubview:searchBar];
[searchBar release];
}
43. - (void)viewDidLoad {
iPhone SDK
[super viewDidLoad];
self.title = NSLocalizedString(@"AppName", nil);
UIBarButtonItem *backBarButtonItem =
[[UIBarButtonItem alloc] initWithImage:
[UIImage imageNamed:@"arrow_left_small.png"]
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[self.navigationItem setBackBarButtonItem:backBarButtonItem];
[backBarButtonItem release];
if (&UIApplicationDidEnterBackgroundNotification) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:
@selector(applicationDidEnterBackground:)
name:
UIApplicationDidEnterBackgroundNotification object:nil];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector
(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector
(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
45. iPhone SDK
init
loadView
viewWillAppear:
animated:
viewDidLoad
viewDidAppear:
animated:
viewWillDisappe
ar:animated:
didReceiveMem
oryWarning viewDidDisappe
ar:animated:
viewDidUnload
dealloc
46. iPhone SDK
initWithNibName:
viewDidLoad
viewWillAppear:
animated:
viewDidAppear:
animated:
viewWillDisappe
ar:animated:
didReceiveMem
oryWarning viewDidDisappe
ar:animated:
viewDidUnload
dealloc
47. iPhone SDK
init
loadView
viewWillAppear:
animated:
viewDidLoad
viewDidAppear:
animated:
viewWillDisappe
ar:animated:
didReceiveMem
oryWarning viewDidDisappe
ar:animated:
viewDidUnload
dealloc
48. iPhone SDK
initWithNibName:
viewDidLoad
viewWillAppear:
animated:
viewDidAppear:
animated:
viewWillDisappe
ar:animated:
didReceiveMem
oryWarning viewDidDisappe
ar:animated:
viewDidUnload
dealloc
50. - (void)loadView {
UIView *contentView =
[[UIView alloc] initWithFrame:
iPhone SDK
CGRectMake(0.0f, 0.0f, 320.0f, 367.0f)];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
[contentView release];
UIImageView *background =
[[UIImageView alloc] initWithImage:[UIImage
imageNamed:@"search_bg.png"]];
[contentView addSubview:background];
[background release];
searchBar = [[UISearchBar alloc] initWithFrame:
CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
searchBar.delegate = self;
searchBar.showsScopeBar = YES;
[[searchBar.subviews objectAtIndex:0]
performSelector:@selector(setBackgroundImage:)
withObject:[UIImage imageNamed:@"searchbar_bg.png"]];
[contentView addSubview:searchBar];
[searchBar release];
}
52. - (void)viewDidLoad {
iPhone SDK
[super viewDidLoad];
self.managedObjectContext =
[[[UIApplication sharedApplication] delegate]
managedObjectContext];
self.store =
[[[UIApplication sharedApplication] delegate] store];
self.searchController =
[[[UISearchDisplayController alloc] initWithSearchBar:searchBar
contentsController:self]
autorelease];
searchController.delegate = self;
searchController.searchResultsDelegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsTableView.hidden = YES;
}
56. [init];
iPhone SDK
[loadView];
[viewDidLoad];
[viewWillAppear:];
[viewDidAppear:];
[viewWillDisappear:];
[viewDidDisappear:];
[didReceiveMemoryWarning];
[viewDidUnload];
[loadView];
[viewDidLoad];
[viewWillAppear:];
[viewDidAppear:];
62. iPhone SDK
[view addSubview:viewController.view];
[init];
[loadView];
[viewDidLoad];
[dealloc];
64. iPhone SDK
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated {
UIView *contentView = viewController.view;
if (animated) {
[UIView beginAnimations:nil context:NULL];
...
}
[viewController viewWillAppear:animated];
[self.view addSubview:contentView];
[viewController viewDidAppear:animated];
...
}
67. iPhone SDK
CornerCase:
popViewControllerAnimated:
72. iPhone SDK
UITextView
UIControl
UITextField, UISwitch
76. iPhone SDK
- (void)diaryUploader:(DiaryUploader *)uploader uploadFailed:(NSError *)
error {
if (error) {
alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"AppName", nil)
message:
[NSString stringWithFormat:@"%@",
[error localizedDescription]]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
[alert show];
[alert release];
}
}
77. iPhone SDK
- (void)viewDidLoad {
[super viewDidLoad];
if (&UIApplicationDidEnterBackgroundNotification) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:
@selector(applicationDidEnterBackground:)
name:
UIApplicationDidEnterBackgroundNotification object:nil];
}
}
78. - (void)alertView:(UIAlertView *)alertView
iPhone SDK
didDismissWithButtonIndex:(NSInteger)buttonIndex {
alert = nil;
}
- (void)applicationDidEnterBackground:
(NSNotification *)note {
[alert dismissWithClickedButtonIndex:0
animated:NO];
alert = nil;
if (self.modalViewController) {
[self.modalViewController
dismissModalViewControllerAnimated:NO];
}
}