9. UINavigationController Class
UIViewController : UIResponder : NSObject
property
delegate : The receiver’s delegate or nil if it doesn’t have a delegate.
@property(nonatomic, assign) id<UINavigationControllerDelegate> delegate
navigationBar
The navigation bar managed by the navigation controller. (read-only)
@property(nonatomic, readonly) UINavigationBar *navigationBar
navigationBarHidden
A Boolean value that determines whether the navigation bar is hidden.
@property(nonatomic, getter=isNavigationBarHidden) BOOL navigationBarHidden
toolbar
The custom toolbar associated with the navigation controller. (read-only)
@property(nonatomic,readonly) UIToolbar *toolbar
UIViewController setToolbarItems:animated: .
toolbarHidden
A Boolean indicating whether the navigation controller’s built-in toolbar is visible.
@property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden
topViewController
The view controller at the top of the navigation stack. (read-only)
@property(nonatomic, readonly, retain) UIViewController *topViewController
viewControllers
The view controllers currently on the navigation stack.
@property(nonatomic, copy) NSArray *viewControllers
visibleViewController
The view controller associated with the currently visible view in the navigation interface. (read-only)
@property(nonatomic, readonly, retain) UIViewController *visibleViewController
ViewController view .
10. UINavigationController Class
initWithRootViewController:
Initializes and returns a newly created navigation controller.
- (id)initWithRootViewController:(UIViewController *)rootViewController
popToRootViewControllerAnimated:
Pops all the view controllers on the stack except the root view controller and updates
the display. ( )
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
popToViewController:animated:
Pops view controllers until the specified view controller is at the top of the navigation stack.
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
popViewControllerAnimated:
Pops the top view controller from the navigation stack and updates the display.
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
pushViewController:animated:
Pushes a view controller onto the receiver’s stack and updates the display.
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
setNavigationBarHidden:animated:
Sets whether the navigation bar is hidden.
- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated
setToolbarHidden:animated:
Changes the visibility of the navigation controller’s built-in toolbar.
- (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated
setViewControllers:animated:
Replaces the view controllers currently managed by the navigation controller with the specified items.
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
12. UINavigationBar Class
property
backItem
The navigation item that is immediately below the topmost item on navigation bar’s stack. (read-
only)
@property(nonatomic, readonly, retain) UINavigationItem *backItem
barStyle
The appearance of the navigation bar.
@property(nonatomic, assign) UIBarStyle barStyle
delegate
The navigation bar’s delegate object. NavigationController .
@property(nonatomic, assign) id delegate
items
An array of navigation items managed by the navigation bar.
@property(nonatomic, copy) NSArray *items
Discussion
The bottom item is at index 0, the back item is at index n-2, and the top item is at index n-1, where
n is the number of items in the array.
tintColor
The color used to tint the bar.
@property(nonatomic, retain) UIColor *tintColor
topItem
The navigation item at the top of the navigation bar’s stack. (read-only)
@property(nonatomic, readonly, retain) UINavigationItem *topItem
translucent
A Boolean value indicating whether the navigation bar is only partially opaque.
@property(nonatomic,assign,getter=isTranslucent) BOOL translucent
13. UINavigationBar Class
Instance
popNavigationItemAnimated:
Pops the top item from the receiver’s stack and updates the navigation
bar.
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated
pushNavigationItem:animated:
Pushes the given navigation item onto the receiver’s stack and updates
the navigation bar.
- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)
animated
setItems:animated:
Replaces the navigation items currently managed by the navigation bar
with the specified items.
- (void)setItems:(NSArray *)items animated:(BOOL)animated
UINavigationBar
. UINavigationController
UINavigationController .
14. UINavigationItem Class
property
backBarButtonItem
The bar button item to use when this item is represented by a back button on the navigation bar.
@property(nonatomic, retain) UIBarButtonItem *backBarButtonItem
hidesBackButton
A Boolean value that determines whether the back button is hidden.
@property(nonatomic, assign) BOOL hidesBackButton
leftBarButtonItem
A custom bar item displayed on the left of the navigation bar when this item is the top item.
@property(nonatomic, retain) UIBarButtonItem *leftBarButtonItem
prompt
A single line of text displayed at the top of the navigation bar.
@property(nonatomic, copy) NSString *prompt
rightBarButtonItem
A custom bar item displayed on the right of the navigation bar when this item is the top item.
@property(nonatomic, retain) UIBarButtonItem *rightBarButtonItem
title
The navigation item’s title displayed in the center of the navigation bar.
@property(nonatomic, copy) NSString *title
titleView
A custom view displayed in the center of the navigation bar when this item is the top item.
@property(nonatomic, retain) UIView *titleView
15. UINavigationItem Class
Instance Method
initWithTitle:
Returns a navigation item initialized with the specified title.
- (id)initWithTitle:(NSString *)title
setHidesBackButton:animated:
Sets whether the back button is hidden, optionally animating the transition.
- (void)setHidesBackButton:(BOOL)hidesBackButton animated:(BOOL)animated
hidesBackButton .
setLeftBarButtonItem:animated:
Sets the custom bar item, optionally animating the transition to the view.
- (void)setLeftBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
setRightBarButtonItem:animated:
Sets the custom bar item, optionally animating the transition to the view.
- (void)setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
16. UIBarButtonItem Class
property
action
The selector defining the action message to send to the target object when the user taps this bar button item.
@property(nonatomic) SEL action
customView
A custom view representing the item.
@property(nonatomic, retain) UIView *customView
possibleTitles
The set of possible titles to display on the bar button.
@property(nonatomic, copy) NSSet *possibleTitles
style
The style of the item.
@property(nonatomic) UIBarButtonItemStyle style
target
The object that receives an action when the item is selected.
@property(nonatomic, assign) id target
width
The width of the item.
@property(nonatomic) CGFloat width
17. UIBarButtonItem Class
instance method
initWithBarButtonSystemItem:target:action:
Creates and returns a new item containing the specified system item.
- (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(id)target
action:(SEL)action
initWithCustomView:
Creates and returns a new item using the specified custom view.
- (id)initWithCustomView:(UIView *)customView
initWithImage:style:target:action:
Creates and returns a new item using the specified image and other properties.
- (id)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style target:(id)target
action:(SEL)action
initWithTitle:style:target:action:
Creates and returns a new item using the specified title and other properties.
- (id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target
action:(SEL)action
20. UIImage Class
• A UIImage object is a high-level way to display image data. You
can create images from files, from Quartz image objects, or from
raw image data you receive.
• imageNamed:
Returns the image object associated with the specified filename.
+ (UIImage *)imageNamed:(NSString *)name
21. CLLocation Class
• CLLocation CLLocationManager object
. , , .
• initWithLatitude:longitude:
Initializes and returns a location object with the specified
latitude and longitude.
- (id)initWithLatitude:(CLLocationDegrees)latitude
longitude:(CLLocationDegrees)longitude
22. MKMapView Class
• Map , .
• region , span(horizon & vertical
distance) .
• ( )
• overlay
28. RootViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)
indexPath {
! PhotoDetailViewController *detailViewController = [[PhotoDetailViewController
alloc] initWithNibName:@"PhotoDetailViewController" bundle:nil];
! NSDictionary *photoData = [[self appDelegate].photoArray
objectAtIndex:indexPath.row];
! detailViewController.photoData = photoData;
! [self.navigationController pushViewController:detailViewController animated:YES];
! [detailViewController release];
}
,
initWithNibName:bundle:
Returns a newly initialized view controller with the nib file in the specified bundle.
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
Parameters
nibName
The name of the nib file to associate with the view controller. The nib file name should not contain any leading path
information. If you specify nil, the nibName property is set to nil.
nibBundle
The bundle in which to search for the nib file. This method looks for the nib file in the bundle's language-specific project
directories first, followed by the Resources directory. If nil, this method looks for the nib file in the main bundle.
Return Value
A newly initialized UIViewController object.
29. ,
• File->New File UIViewController subclass
with XIB for user interface
• PhotoMapViewController .
• PhotoMapViewController.xib IB Simulated User Interface
Elements Top Bar .
• MapView
UIView & .
30. PhotoMapViewController.h .m
PhotoMapViewController.h
@interface PhotoMapViewController : UIViewController <MKMapViewDelegate> {
! NSDictionary *photoData;
! MKMapView *mapView;
}
@property (retain) NSDictionary *photoData;
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@end
#import "PhotoMapViewController.h"
@implementation PhotoMapViewController
@synthesize mapView;
@synthesize photoData;
0 1 1 111km
- (void)viewDidLoad {
[super viewDidLoad];
! mapView.delegate = self;
!
}
- (void)viewWillAppear:(BOOL)animated
{
! CLLocation *location = [photoData valueForKey:@"Location"];
! MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.1);
! MKCoordinateRegion region = MKCoordinateRegionMake(location.coordinate, span);
! [mapView setRegion:region animated:YES];
}
- (void)dealloc {
!
!
[photoData release];
[mapView release];
setRegion:animated:
[super dealloc]; Changes the currently visible region and optionally animates the change.
}
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated
@end Parameters
region
The new region to display in the map view.
animated
Specify YES if you want the map view to animate the transition to the new region or NO if
you want the map to center on the specified region immediately
32. -goToMapView:
PhotoDetailViewController.m
- (IBAction)goToMapView:(id)sender
{
! PhotoMapViewController *mapViewController = [[PhotoMapViewController alloc]
initWithNibName:@"PhotoMapViewController" bundle:nil];
! mapViewController.photoData = photoData;
! [self.navigationController pushViewController:mapViewController animated:YES];
! [mapViewController release];
}
UIViewController Class
navigationController
A parent or ancestor that is a navigation controller. (read-only)
@property(nonatomic, readonly, retain) UINavigationController
*navigationController
Discussion
Only returns a navigation controller if the view controller is in its stack. This property is nil if a navigation
controller cannot be found.