• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
아이폰강의(5) pdf
 

아이폰강의(5) pdf

on

  • 877 views

 

Statistics

Views

Total Views
877
Views on SlideShare
723
Embed Views
154

Actions

Likes
0
Downloads
7
Comments
0

3 Embeds 154

http://www.sunoo.net 130
http://sunoo.net 22
http://denny0326.tistory.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    아이폰강의(5) pdf 아이폰강의(5) pdf Presentation Transcript

    • Chapter 7 Natural born navigator Bit Academy
    • • • • . •
    • • • • ViewController ViewController .
    • Navigation • UIViewController : UIView • UINavigationController : NavigationBar NavigationBar . • UINavigationBar : , UINavigationController • UINavigationItem : UIViewController , UINavigationBar , leftBarButtonItem, rightBarButtonItem . • UIBarButtonItem : , UIButton -
    • UIViewController Class • . , . • . • NIB . NIB IB . • loadView NIB initWithNibName:bundle: NIB .
    • Creating a View Controller Using Nib Files 1 – initWithNibName:bundle: 2   nibName  property 3   nibBundle  property Managing the View 1   view  property 2 – loadView 3 – viewDidLoad 4 – viewDidUnload 5 – isViewLoaded 6   title  property 7   contentSizeForViewInPopover  property 8   modalInPopover  property Responding to View Events 1 – viewWillAppear: 2 – viewDidAppear: 3 – viewWillDisappear: 4 – viewDidDisappear: Configuring the View’s Layout Behavior 1   wantsFullScreenLayout  property Configuring the View Rotation Settings 1   interfaceOrientation  property 2 – shouldAutorotateToInterfaceOrientation: 3 – rotatingHeaderView 4 – rotatingFooterView Responding to View Rotation Events 1 – willRotateToInterfaceOrientation:duration: 2 – willAnimateRotationToInterfaceOrientation:duration: 3 – didRotateFromInterfaceOrientation: 4 – willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: 5 – didAnimateFirstHalfOfRotationToInterfaceOrientation: 6 – willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
    • Handling Memory Warnings 1 – didReceiveMemoryWarning Getting Other Related View Controllers 1   parentViewController  property 2   searchDisplayController  property 3   splitViewController  property 4   modalViewController  property 5   navigationController  property 6   tabBarController  property Presenting Modal Views 1 – presentModalViewController:animated: 2 – dismissModalViewControllerAnimated: 3   modalTransitionStyle  property 4   modalPresentationStyle  property 5 – disablesAutomaticKeyboardDismissal Configuring a Navigation Interface 1   navigationItem  property 2   editing  property 3 – setEditing:animated: 4 – editButtonItem 5   hidesBottomBarWhenPushed  property Configuring the Navigation Controller’s Toolbar 1 – setToolbarItems:animated: 2   toolbarItems  property Configuring Tab Bar Items 1   tabBarItem  property
    • UINavigationController ClassUIViewController : 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 .
    • 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
    • UINavigationController Delegate Protocol delegate protocol UINavigationController delegate Instance Methods navigationController:didShowViewController:animated: . - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated navigationController:willShowViewController:animated: . - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    • 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
    • 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 .
    • 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
    • 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
    • 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
    • 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
    • - pushViewController:animated: - - navigationItem navigationBar - back navigationItem navigationBar
    • •2 • : •1 : •2 :
    • 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
    • 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
    • MKMapView Class • Map , . • region , span(horizon & vertical distance) . • ( ) • overlay
    • • File->NewProject • Navigation-based Application • : WorldPhotos • Window.xib RootViewController.nib
    • WorldPhotosAppDelegate.h @interface WorldPhotosAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UINavigationController *navigationController;WorldPhotosAppDelegate.m ! ! NSArray *photoArray;- (void)applicationDidFinishLaunching:(UIApplication *)application { }! photoArray = [[NSArray alloc] initWithArray:[self createPhotoData]];! [window addSubview:[navigationController view]]; - (NSArray *)createPhotoData; [window makeKeyAndVisible];} @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController- (NSArray *)createPhotoData *navigationController;{ @property (readonly) NSArray *photoArray;! CLLocation *location; @end! UIImage *photo;! UIImage *thumbnail;!! location = [[CLLocation alloc] initWithLatitude:31.048026 longitude:-7.13017];! photo = [UIImage imageNamed:@"Africa_Morocco_1.jpg"];! thumbnail = [UIImage imageNamed:@"Africa_Morocco_1_thumbnail.jpg"];! NSDictionary *africa_morroco = [NSDictionary dictionaryWithObjectsAndKeys:@"Africa", @"Region", @"Morocco", @"Country", photo,@"Photo", thumbnail, @"Thumbnail", location, @"Location", nil];! [location release]; - method!! location = [[CLLocation alloc] initWithLatitude:35.700884 longitude:139.770893];! photo = [UIImage imageNamed:@"Asia_Japan_1.jpg"];! thumbnail = [UIImage imageNamed:@"Asia_Japan_1_thumbnail.jpg"];! NSDictionary *asia_japan = [NSDictionary dictionaryWithObjectsAndKeys:@"Asia", @"Region", @"Japan", @"Country", photo, @"Photo",thumbnail, @"Thumbnail", location, @"Location", nil];! [location release];!! location = [[CLLocation alloc] initWithLatitude:46.981248 longitude:8.253908];! photo = [UIImage imageNamed:@"Europe_Swiss_1.jpg"];! thumbnail = [UIImage imageNamed:@"Europe_Swiss_1_thumbnail.jpg"];! NSDictionary *europe_swiss = [NSDictionary dictionaryWithObjectsAndKeys:@"Europe", @"Region", @"Swiss", @"Country", photo, @"Photo",thumbnail, @"Thumbnail", location, @"Location", nil];! [location release];!! NSArray *returnArray = [NSArray arrayWithObjects:africa_morroco, asia_japan, europe_swiss, nil];! return returnArray;}
    • ,RootViewController.m@implementation RootViewController RootViewController.h- (void)viewDidLoad { [super viewDidLoad]; @class WorldPhotosAppDelegate;! self.navigationItem.title = @"World Photos";} @interface RootViewController : UITableViewController { }- (WorldPhotosAppDelegate *)appDelegate{ - (WorldPhotosAppDelegate *)appDelegate;! return [[UIApplication sharedApplication] delegate]; @end}#pragma mark Table view methods- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { //optional return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[self appDelegate].photoArray count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; }! NSDictionary *photoData = [[self appDelegate].photoArray objectAtIndex:indexPath.row];!! cell.textLabel.text = [photoData valueForKey:@"Country"];! cell.detailTextLabel.text = [photoData valueForKey:@"Region"];! cell.imageView.image = [photoData valueForKey:@"Thumbnail"];! cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell;}- (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];}
    • ,-file->new Choose template UIViewController subclassPhotoDetailViewController . PhotoDetailViewController.h .m .xib .PhotoDetailView.xib IB ImageViewUIView & .PhotoDetailView.h NSDictionary photoData, UIImageView OutLet photoImageView, UIBarButtonItem OutLet mapBarButtonmapBarButton goToMapView: . Bar Button Items Nib & mapBarButton , Map . photoDetailViewController .mapBarButton File’s Owner PhotoDetailViewController -goToMapView: . . PhotoViewController view -viewDidLoad . rightBarButtonItem view
    • PhotoDetailViewController.h .m PhotoDetailViewController.h @interface PhotoDetailViewController : UIViewController { ! NSDictionary *photoData; ! UIImageView *photoImageView; ! ! UIBarButtonItem *mapBarButton; } - (IBAction)goToMapView:(id)sender; @property (retain) NSDictionary *photoData; @property (nonatomic, retain) IBOutlet UIImageView *photoImageView; @property (nonatomic, retain) IBOutlet UIBarButtonItem *mapBarButton; @end PhotoDetailViewController.m #import "PhotoDetailViewController.h" #import "PhotoMapViewController.h" @implementation PhotoDetailViewController @synthesize photoData; @synthesize photoImageView; @synthesize mapBarButton; - (void)viewDidLoad { [super viewDidLoad]; ! self.navigationItem.rightBarButtonItem = mapBarButton; ! photoImageView.image = [photoData valueForKey:@"Photo"]; } - (void)dealloc { ! [photoData release]; ! [photoImageView release]; ! [mapBarButton release]; [super dealloc]; } - (IBAction)goToMapView:(id)sender { ! PhotoMapViewController *mapViewController = [[PhotoMapViewController alloc] initWithNibName:@"PhotoMapViewController" bundle:nil]; ! mapViewController.photoData = photoData; ! [self.navigationController pushViewController:mapViewController animated:YES]; ! [mapViewController release]; } @end
    • 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 bundles 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.
    • , • File->New File UIViewController subclass with XIB for user interface • PhotoMapViewController . • PhotoMapViewController.xib IB Simulated User Interface Elements Top Bar . • MapView UIView & .
    • 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
    • • PhotoDetailViewController PhotoMapViewController Map . • callback PhotoDetailViewController -goToMapView: . • PhotoMapViewController pushViewController: MapView .
    • -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.