본문 바로가기

PDA&Mobile

아이폰 앱 개발 팁(6) : Stanford Lecture #7

* 본 포스트는 Blog.MissFlash.com에서 작성한 것으로, 원문 저작자의 동의없이 마음대로 퍼가실 수 없습니다. 포스트의 내용이 마음에 드시면 링크를 이용해주시면 감사하겠습니다.

> Stanford Lecture #7

* Push to add a view controller
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;

* Pop to remove a view controller
- (void)popViewControllerAnimated:(BOOL)animated;

* Pushing your first view controller
- (void)applicationDidFinishLaunching:(UIApplication *)application {
navController = [[UINavigationController alloc] init];
[navController pushViewController:firstViewController animated:NO];
[window addSubview:navController.view];
}

* Push from within a view controller on the desk
- (void)myAction:(id)sender{
UIViewController *viewController = ...;
[self.navigationController pushViewController:viewController animated:YES];
}

* Text bar button item
- (void)viewDidLoad{
UIBarButtonItem *fooButton = [[UIBarButtonItem alloc] initWithTitle:@"Foo" style:UIBarButtonItemStyleBordered target:self action:@selector(foo:)];
self.navigationItem.leftBarButtonItem = fooButton;
[fooButton release];
}

* System bar button item
- (void)viewDidLoad{
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd style:UIBarButtonItemStyleBordered target:self action:@selector(add:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}

* Edit/Done button
self.navigationItem.leftBarButtonItem = self.editButtonItem;
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
// Update appearance of views
}

* Custom title view
UISegmentedControl *segmentedControl = ...;
self.navigationItem.titleView = segmentedControl;
[segmentedControl release];

* Back button
self.title = @"Hello there, CS193P!";
UIBarButtonItem *heyButton = [[UIBarButtonItem alloc] initWithTitle:@"Hey!" ...];
self.navigationItem.backButtonItem = heyButton;
[heyButton release];
vs.

* Setting up a Tab Bar controller
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = myViewControllers;
[window addSubview:tabBarController.view];
}

* Creating Tab Bar items : Title and image
- (void)viewDidLoad{
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Playlists" image:[UIImage imageNamed:@"music.png"] tag:0];
}

* Creating Tab Bar items : System item
- (void)viewDidLoad{
self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:0];
}

* Nesting Navigation Controllers
- Create a Tab Bar controller
tabBarController = [[UITabBarController alloc] init];

- Create each Navigation controller
navController = [[UINavigationController alloc] init];
[navController pushViewController:firstViewController animated:NO];

- Add them to the Tab Bar controller
tabBarController.viewControllers = [NSArray arrayWithObjects:navController, anotherNavController, someViewController, nil];