The document discusses iOS application development. It provides details on view controllers, navigation controllers, tab bar controllers and their life cycles. It describes how to create and link view controllers to allow navigation between screens in an app. It also discusses customizing navigation bar buttons, titles and tab bar items. The key topics covered are view controller hierarchies, passing data between view controllers, and using navigation and tab bar controllers to structure app navigation and organization.
6. как изменять позиции
при вращении?
ur View with Interface Builder
Interface Builder
w controller class
let
oller
Name:bundle:
7. UINavigationController
UINavigationController
UINavigationController
• Stack of view controllers
• Stack of • Navigation bar
view controllers
• Navigation bar
View Controller
View Controller
Navigation View Controller
Navigation Controller View Controller
Controller View Controller
View Controller
Thursday, January 28, 2010 5
Thursday, January 28, 2010 5
8. управление набором
ViewController
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated;
!!!вызывается retain
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
pop обычно не вызывается, автоматически при нажатии ‘<-’
10. а как использовать?
- (void)someAction:(id)sender {
}
UIViewController *viewController = ...;
[self.navigationController pushViewController:viewControlle animated:YES];
}
11. посмотрим?
•New Window-Based app
•Новый ViewController с кнопкой
•NavigationController и FirstViewController в AppDelegate
•SecondViewController
•Cвойство title у ViewController
13. как связать все
ViewController?
• Не стоит использовать глобальные
переменные или AppDelagate
• Что нужно на входе следующему
ViewController?
14. как связать все
ViewController?
Best Practices for Data Flow
• Не стоит использовать глобальные
• Figure out exactly what needs to be communicated
переменные или AppDelagate
• Define input parameters for your view controller
• Что нужно на входе следующему
ViewController?
Data
List Detail
Controller Controller
Thursday, January 28, 2010 16
15. как связать все
ViewController?
Best Practices for Data Flow
• Не стоит использовать глобальные
• Figure out exactly what needs to be communicated
переменные или AppDelagate
• Define input parameters for your view controller
• Что нужно на входе следующему
ViewController?
Data
List Detail
Controller Controller
• В обратную сторону - используя делегаты
(с помощью протоколов)
Thursday, January 28, 2010 16
16. Customizing Navigation
бонусы к навигации
• Buttons or custom controls
• Interact with the entire screen
Thursday, January 28, 2010 20
17. UINavigationTitle
• Содержится у любогоOwnership
Navigation Item ViewController
Left Bar
Button Item
View Controller Navigation Item Title View
Right Bar
Button Item
18. кнопки справа и слева
• UIBarButtonItem отображается сверху
• Отображает строку, изображение
• Target + Action (как и во всех кнопках)
20. кнопка
редактирования
Edit/Done Button
•
• Very common pattern практика
реализованная
• Every view controller has one available
! Target/action already set up
self.navigationItem.leftBarButtonItem = self.editButtonItem;
self.navigationItem.leftBarButtonItem = self.editButtonItem;
// Called when the user toggles the edit/done button
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
}
{
// Update appearance of views
}
21. Custom Title View вместо надписи
• Arbitrary view in place of the title
UISegmentedControl *segmentedControl = ...
self.navigationItem.titleView = segmentedControl;
[segmentedControl release];
Thursday, January 28, 2010 28
22. UITabBarController
UITabBarController
UITabBarController
• Array of view controllers
• Tab bar
• Array of view controllers
• Tab bar
View Controller
Tab Bar
View Controller
Controller
View Controller
Tab Bar
Controller
Thursday, January 28, 2010 32
24. добавляем картинку и
Creating Tab надпись
Bar Items
• Title and image
- (void)viewDidLoad
{
UITabBarItem *item = [[UITabBarItem alloc]
initWithTitle:@“Playlists”
image:[UIImage imageNamed:@“music.png”]
tag:0];
self.tabBarItem = item;
[item release];
}
25. стандартный набор
Creating Tab Bar Items
• System item
- (void)viewDidLoad
{
UITabBarItem *item = [[UITabBarItem alloc]
initWithTabBarSystemItem:
UITabBarSystemItemBookmarks
tag:0]
self.tabBarItem = item;
[item release];
}
Thursday, January 28, 2010 37
26. ollers
а если слишком
More View Controllers
• много?
b bar controller has too many a tab bar controller has too many
What happens when
y at once? view controllers to display at once?
! “More” tab bar item
displayed automatically
! User can navigate to
remaining view controllers
27. Tab Bar + Navigation Controllers
Multiple parallel hierarchies
Thursday, January 28, 2010 41
28. архитектура
Tab Bar + Navigation Controllers
Navigation
Controller View Controller
Navigation
Tab Bar Controller Controller View Controller
View Controller