수업 진행 UINavigationController ( 목 ) Animation ( 목 ) TabBarViewController ( 목 ) UITableViewController ( 금 ) CoreLocation ( 토 )

Slides:



Advertisements
Similar presentations
Integrating Facebook into iOS Apps 08/25/2011 North Atlanta iOS Developers Meetup Group Presentation.
Advertisements

Chapter 3 – Web Design Tables & Page Layout
Table Views UITableView. Overview Table view basics Tables display lists of data Each item in a tables list is a row Tables can have an unlimited number.
TableView and TableViewController
Copyright 2003 Peter McDevitt 1 Microsoft Excel 2002 Lecture 3 – A Professional Looking Worksheet.
Site Modules > Page Builder Access the Page Builder module through the Site Modules top navigation link. Access Page Builder from the Site Modules navigation.
COE201 – Computer Proficiency Mr. Hamze Msheik
The Problem: iPhone UI Navigation I want to have a TableView that works INSIDE a TabView.
IPhone 101. Outline Objective-C Random bits of the API Using the simulator Debugging with Xcode.
IOS and Location Services CS4521. Core Location Core Location Framework to determine the current latitude and longitude of a device Core Location uses.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Access Lesson 4 Creating and Modifying Forms
Software Apps. Word, PowerPoint, Excel, Access Mr. Miller.
Copyright © Texas Education Agency, All rights reserved. 1 Web Technologies Website Development with Dreamweaver.
Xcode Presentation Tom Pletzke. Creating App from template Launch Xcode Select Tabbed Application.
iOS components in Swift
1 Designing with a UIToolBar iPhone/iPad, iOS Development Tutorial.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
Navigation in iPads splitViewController. Overview Create a Master-Detail application Switch Device Family to iPad Give the project a name and click “Use.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Course Summary Xcode & iPhone Simulator
Nav Controllers UINavigationController. Overview Nav Controller basics Like a tabview controller, a navViewController manages views A navigationViewController.
User Interface Objects From Beginning iPhone 4 Development and The iPhone Developer’s Cookbook (Chapter 4)
By: Ms. Abeer Helwa 1. CREATE A WORD DOCUMENT 2 Blank document Templates To create a new blank document: click the File tab and click Blank document.
Table Views UITableView.
1 UI Alert View iPhone/iPad, iOS Development Tutorial.
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
Web Site Development - Process of planning and creating a website.
Building a Website: Layout Fall Overall Structure: Home Page Title Section Title Frame Picture UNCP Math Menu Content Footer Contact Information.
1 Word Processing Intermediate Using Microsoft Office 2000.
DAY 25: WORD CHAPTER Rohit March 28,
이미지 뷰의 애니메이션 이미지 뷰는 자체적으로 애니메이션 기능을 제공하고 있습니다.
1 디바이스 정보  UIDevice 클래스가 제공하고 static 메서드인 currentDevice 가 객체를 생성합 니다.  제공하는 정보 uniqueIdentifier: 장치 고유 ID / 회원가입을 하지 않고 어플을 운영 가능 model: 모델명 systemVersion:
Lec 12 Pickers CS 3800 Introduction to IOS programming Lecture 12 Summer 2011.
© 2004 The McGraw-Hill Companies, Inc. All rights reserved. The Advantage Series Microsoft Office Word 2003 CHAPTER 4 Printing and Web Publishing.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 5 BACKNEXTEND 5-1 LINKS TO OBJECTIVES Using the Form Button Using the Form Button Form Views.
Course Summary Xcode & iPhone Simulator
Location And Maps Sisoft Technologies Pvt Ltd
Excel Tutorial 8 Developing an Excel Application
Views in iOS Mobile apps for iPhone & iPad Telerik Software Academy
Drawing And Animations
IOS Design Patterns Sisoft Technologies Pvt Ltd
Microsoft Access 2007 – Level 2
iOS UI Components Sisoft Technologies Pvt Ltd
iOS - First Application Anatomy
Creating a Word Document – Part 1
Designing with Introspection
Microsoft Excel A Spreadsheet Program.
UITableView API A table view is an instance of the UITableView class. Created given... an area on the screen, and A table style. Rows are created using.
Introduction to the Visual C# 2005 Express Edition IDE
View-Controller Family
What is UI Element in iPhone Development?
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
Chapter 1 Editing a Photo
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
Tutorial 3 – Creating a Multiple-Page Report
DREAMWEAVER MX 2004 Chapter 3 Working with Tables
CSC 581: Mobile App Development
Creating a Word Document – Part 1
EEC-492/693/793 iPhone Application Development
CSC 581: Mobile App Development
Using Templates and Library Items
EEC-492/693/793 iPhone Application Development
Practice Activity – Part 1
Guidelines for Microsoft® Office 2013
Welcome To Microsoft Word 2016
Presentation transcript:

수업 진행 UINavigationController ( 목 ) Animation ( 목 ) TabBarViewController ( 목 ) UITableViewController ( 금 ) CoreLocation ( 토 )

UIViewControllerUITabBarController UINavigationController UITableViewController ABNewPersonViewController UINavigationItem UIBarItem UITabBarItem UIBarButtonItem Class 구조

Listing 3-1 Setting up the root view controller—window in nib file - (void)applicationDidFinishLaunching:(UIApplication *)application { RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain]; NSArray *timeZones = [NSTimeZone knownTimeZoneNames]; rootViewController.timeZoneNames = [timeZones UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; self.navigationController = aNavigationController; [aNavigationController release]; [rootViewController release]; [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; }

Listing 3-2 Setting up the root view controller—window created programmatically - (void)applicationDidFinishLaunching:(UIApplication *)application { // Create the window window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Create the navigation and view controllers RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain]; navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; [rootViewController release]; // Configure and show the window [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; }

네비게이션 바와 컨트롤러 p105

UINavigation Controller The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content.

UINavigation Controller

The views of a navigation controller

UINavigationController Property

you do not have to pop view controllers off the stack programmatically. Instead, the navigation controller provides a back button on the navigation bar, that when tapped, pops the topmost view controller automatically UINavigationController Stack

UINavigationBar Property

[ [ [ UIBarButtonItem alloc ] [ [ [ UIBarButtonItem alloc ] initWithImage:[UIImage self.navigationItem.prompt = [NSString click a button now"];

UINavigationBar Property 보통 뷰 컨트롤러의 init 메소드에서 설정 UINavigationItem - 내부클래스 타이틀 설정 self.title Box”;

How To Programming?

UINavigation Controller 생성 NIB

UINavigation Controller 생성 Programmatically viewCont = [[MyViewController alloc] init]; navigationCont = [[UINavigationController alloc] initWithRootViewController:viewCont]; 윈도우에 네비게이션 컨트롤러 추가 [window addSubview:[navigationCont view]]; 다른 뷰를 네비게이션 컨트롤러에 추가시 [navigationCont pushViewController:myOtherViewCont animated:YES]; 네비게이션 컨트롤러 관리 방식 : 스택 뒤로 가기 버튼의 타이틀 = 뷰 컨트롤러의 타이틀 viewCont = [[MyViewController alloc] init]; navigationCont = [[UINavigationController alloc] initWithRootViewController:viewCont]; [window addSubview:[navigationCont view]]; [navigationCont pushViewController:myOtherViewCont animated:YES];

버튼, 스타일 액션 UIBarButtonItem *myButton = [ [ [ UIBarButtonItem alloc] it!” style: UIBarButtonItemStylePlain target: self ] autorelease ]; UIBarButtonItemStylePlain UIBarButtonItemStyleBordered UIBarButtonItemStyleDone - (void)doit{ /* 버튼이 눌렸을 때 작업할 소스 작성 */ } self.navigationItem.leftBarButtonItem = nil; self.navigationItem.leftBarButtonItem.enabled = NO; UIBarStyleDefault UIBarStyleBlackOpaque UIBarStyleBlackTranslucent UINavigation Controller Property

UISegmentedControl - TitleView UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWIthItems:nil]; segmentControl.segmentedControlStyle = UISegmentedControlStyleBar; [segmentedControl atIndex:0 animated:NO]; [segmentedControl new” atIndex:1 animated:NO]; [segmentedControl atIndex:2 animated:NO]; self.navigationItem.titleView = segmentedControl; [segmentedControl addTarget:self forControlEvents:UIControlEventValueChanged]; - (void) controllerPressed: (id)sender{ UISegmentControl *segmentControl = (UISegmentControl *)sender; int selectedIndex = [segmentControl selectedSegmentIndex]; /* 처리 */ }

ToolBar 추가

이미지와 텍스트 버튼 NSMutableArray *buttons = [[NSMutbleArray alloc] init]; UIBarButtonItem *buttonImage = [[UIBarButtonItem alloc] initWithImage: [UIImage style: UIBarButtonItemStylePlain target:self ]; initWithCustomView:myView];... initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks... UIBarButtonItem.h 참고

ToolBar 추가 이미지와 텍스트 버튼 UIBarButtonItem.h 참고 [buttons addObject: buttonImage]; [buttons addObject: buttonText]; [buttons addObject: myBookmarks]; UIToolbar *toolbar = [[UIToolbar alloc] init]; [toolbar setItems: buttons animated: YES]; self.navigationItem.titleView = toolbar; [toolbar sizeToFit]; toolbar.barStyle = UIBarStyleDefault; UIBarStyleDefault UIBarStyleBlackOpaque UIBarStyleBlackTranslucent

Modifying the Navigation Stack

pushViewController:animated: Display the next level of hierarchical data. popViewControllerAnimated: Back up one level in the hierarchy. setViewControllers:animated: Restore the navigation stack to a previous state. popToRootViewControllerAnimated: Return the user to the root view controller. popToViewController:animated: Back up an arbitrary number of levels in the hierarchy.

sample 실습

sample 응용 1. UpDownNavbar

sample 응용 세번째 세그먼트 추가 및 액션 설정 UInavigationBar 에 두개의 버튼 추가, 작동하도록 UIbarButtonSystemItemAdd 버튼 적용 스택 이동 (top, depth3 -> depth1)

전환 애니메이션 p123

ModalViewController Animation int styles[3] = {UIModalTransitionStyleCoverVertical, UIModalTransitionStyleCrossDissolve, UIModalTransitionStyleFlipHorizontal }; InfoViewController *ivc = [[[InfoViewController alloc] init] autorelease]; ivc.modalTransitionStyle = styles[segment]; [self presentModalViewController:ivc animated:YES];

CGContextRef #define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease] - (void) fadeOut: (id) sender { CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; [[self.view viewWithTag:999] setAlpha:0.0f]; [UIView commitAnimations]; self.navigationItem.rightBarButtonItem = } - (void) fadeIn: (id) sender { CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; [[self.view viewWithTag:999] setAlpha:1.0f]; [UIView commitAnimations]; self.navigationItem.rightBarButtonItem = } CoreGraphics.framework 추가

CATransition 쿼츠코어 : 전환하는 동안의 모든 그래픽을 처리하는 새로운 스래드 생성 QuartzCore.framework 추가 CATransition *animation = [CATransition animation]; [animation setDelegate:self]; [animation setDuration:1.0f]; [animation setTimingFunction:UIViewAnimationCurveEaseInOut]; [animation setType: kCATransitionPush]; [animation setSubtype: kCATransitionFromLeft]; [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; [[[self superview] layer] addAnimation:animation Timing 함수 애니메이션타입 지속시간 애니메이션서브타입추가 [self.view.layer addAnimation:myTransition forKey:nil];[self.view addSubview:newView]; [oldView removeFromSuperview];

sample 실습 FlipDemo: 페이지 넘기기

sample 응용 다른 타입의 페이지 transition 이용 프로토타입 CAAnimation.h CAMediaTimingFunction.h CALayer.h

// CATransition *animation = [CATransition animation]; animation.delegate = self; animation.duration = 0.3f; animation.timingFunction = (CAMediaTimingFunction *)UIViewAnimationCurveEaseInOut; animation.type = kCATransitionPush; animation.subtype = fromTop ? kCATransitionFromTop : kCATransitionFromBottom; // Perform the animation [self.animationView exchangeSubviewAtIndex:[self.animationView.subviews indexOfObject:self.view] withSubviewAtIndex:[self.animationView.subviews indexOfObject:self.view]]; [self.middleTableView reloadData]; [[self.animationView layer] addAnimation:animation 앞서 만들었던 네비게이션 바 버튼에 CATransition 적용

TabBar p393

탭바 컨트롤러 UITabBar 여러개의 서로 다른 뷰와 이동을 관리하기 편하도록 탭바와 UITabBarController 클래스를 캡슐화 Property - 뷰 컨트롤러 의존 레이블 - 컨트롤러 대신 뷰에 속함

The UITabBarController class implements a specialized view controller that manages a radio-style selection interface. This class is not intended for subclassing. Instead, you use instances of it as-is to present an interface that allows the user to choose between different modes of operation. This tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode.

Accessing the Tab Bar Controller Properties delegate property tabBar property Managing the View Controllers viewControllers property setViewControllers:animated: customizableViewControllers property moreNavigationController property Managing the Selected Tab selectedViewController property selectedIndex property

탭바 컨트롤러 생성 컬렉션 만들기 버튼 Property 설정 NSMutableArray *array = [ [ NSMutableArray alloc ] init ]; [ array addObject: firstViewController ]; [ array addObject: secondViewController ]; - (id) init{ self = [super init]; if (self !=nil) { self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:self.title image:image tag:0] autorelease]; } return self; } self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemFavorites tag:4

탭바 컨트롤러 생성 탭바 컨트롤러 보여주기 UITabBArController *tabBarController = [[UITabBarController alloc] init]; tabBarController.viewControllers = viewControllers [window addSubview:tabBarConroller.view]; [window makeKeyAndVisible]; IB 에서 생성 가능

수정 가능한 버튼 Navigation tbarController.customizableViewControllers = controllers; tbarController.customizableViewControllers = nil; tabBarController.selectedViewController = myGameViewController; UIViewController *activeController = tabBarController.selectedViewController; if (acriveController == myGameViewControllers){ /* myGameViewController 를 활성화 시킨다 */ } tabBarController.selectedIndex = 3;

델리게이트 액션 tabBarController.delegate = self; #pragma delegate - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ // NSNumber *tabNumber = [NSNumber numberWithInt:[tabBarController selectedIndex]]; UIAlertView *aAlertView = [[UIAlertView alloc] initWithTitle:[NSString 탭 ", tabBarController.selectedIndex] 선택함 " delegate:nil cancelButtonTitle:nil 확인 ", nil]; [aAlertView show]; }

델리게이트 액션 - (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed { for (UIViewController *vc in viewControllers) { vc vc.title); } :04: TabDemo[6168:207] customized vc (title=Page 5) :04: TabDemo[6168:207] customized vc (title=Page 1) :04: TabDemo[6168:207] customized vc (title=Page 6) :04: TabDemo[6168:207] customized vc (title=Page 3) :04: TabDemo[6168:207] customized vc (title=Page 0) :04: TabDemo[6168:207] customized vc (title=Page 2) :04: TabDemo[6168:207] customized vc (title=Page 4) :04: TabDemo[6168:207] customized vc (title=Page 7)

Managing Tab Bar Selections – tabBarController:shouldSelectViewController: – tabBarController:didSelectViewController: Managing Tab Bar Customizations – tabBarController:willBeginCustomizingViewControllers: – tabBarController:willEndCustomizingViewControllers:changed: – tabBarController:didEndCustomizingViewControllers:changed: UITabBarControllerDelegate

sample 실습 Tabbar Demo

sample 응용 3 번째 탭을 선택하면 자동으로 4 번째 탭 선택 되도록 프로토타입 UITabBar.h UITabBarController.h UITabBarItem.h

테이블 뷰와 뷰 컨트롤러 p140

목차 UITableViewController UITableView Delegate / Datasource UITableCell Accessary swipe-to-delete / table reload

테이블 뷰 컨트롤러 종류

New -> Project -> UITableViewControlle r

Figure 1-1 A table view in the plain style (no section header or footer) Figure 1-2 A table view configured as an section index 여러가지 테이블 뷰 컨트롤러

Figure 1-3 A table view configured as an selection list Figure 1-4 A table view in the grouped style 여러가지 테이블 뷰 컨트롤러

Figure 1-5 Header and footer of a section 테이블 뷰 구성 Configuring a Table View – dequeueReusableCellWithIdentifier: style property – numberOfRowsInSection: – numberOfSections rowHeight property separatorStyle property separatorColor property backgroundView property tableHeaderView property tableFooterView property sectionHeaderHeight property sectionFooterHeight property sectionIndexMinimumDisplayRowCount prop erty

테이블 뷰 구성 Configuring a Table View – dequeueReusableCellWithIdentifier: style property – numberOfRowsInSection: – numberOfSections rowHeight property separatorStyle property separatorColor property backgroundView property tableHeaderView property tableFooterView property sectionHeaderHeight property sectionFooterHeight property sectionIndexMinimumDisplayRowCount prop erty tableHeaderView tableFooterView UITableCell backgroundView

// // UITableViewController.h // UIKit // // Copyright Apple Inc. All rights reserved. // #import UITableViewController : UIViewController UITableViewStyle _tableViewStyle; id _keyboardSupport; struct { int clearsSelectionOnViewWillAppear:1; } _tableViewControllerFlags; } - UITableView BOOL clearsSelectionOnViewWillAppear __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_3_2); // defaults to YES. If YES, any selection is cleared in

UITableViewDataSource? UITableViewDelegate?

UITableViewDataSource Configuring a Table View – tableView:cellForRowAtIndexPath: required method – numberOfSectionsInTableView: – tableView:numberOfRowsInSection: required method – sectionIndexTitlesForTableView: – tableView:sectionForSectionIndexTitle:atIndex: – tableView:titleForHeaderInSection: – tableView:titleForFooterInSection: Inserting or Deleting Table Rows – tableView:commitEditingStyle:forRowAtIndexPath: – tableView:canEditRowAtIndexPath: Reordering Table Rows – tableView:canMoveRowAtIndexPath: – tableView:moveRowAtIndexPath:toIndexPath:

UITableViewDelegate Configuring Rows for the Table View – tableView:heightForRowAtIndexPath: – tableView:indentationLevelForRowAtIndexPath: – tableView:willDisplayCell:forRowAtIndexPath: Managing Accessory Views – tableView:accessoryButtonTappedForRowWithIndexPath: – tableView:accessoryTypeForRowWithIndexPath: Deprecated in iOS 3.0 Managing Selections – tableView:willSelectRowAtIndexPath: – tableView:didSelectRowAtIndexPath: – tableView:willDeselectRowAtIndexPath: – tableView:didDeselectRowAtIndexPath:

UITableViewDelegate Modifying the Header and Footer of Sections – tableView:viewForHeaderInSection: – tableView:viewForFooterInSection: – tableView:heightForHeaderInSection: – tableView:heightForFooterInSection: Editing Table Rows – tableView:willBeginEditingRowAtIndexPath: – tableView:didEndEditingRowAtIndexPath: – tableView:editingStyleForRowAtIndexPath: – tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: – tableView:shouldIndentWhileEditingRowAtIndexPath: Reordering Table Rows – tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:

테이블 생성 / 테이블 셀 바인딩 요청에 응답하는 딜리게이트 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [ fileList objectAtIndex: [ indexPath indexAtPosition: 1 ] ]; UITableViewCell *cell = [ tableView dequeueReusableCellWithIdentifier: CellIdentifier ]; if (cell == nil) { cell = [ [ [ UITableViewCell alloc ] initWithFrame: CGRectZero reuseIdentifier: CellIdentifier ] autorelease ]; cell.text = CellIdentifier; cell.textAlignment = UITextAlignmentLeft; // Left, Right, Center cell.selectedStyle = UITableViewCellSElectionStyleBlue; // Gray, None cell.textColor = [UIColor redColor]; cell.selectedTextColor = [UIColor blueColor]; cell.image = [UIImage } return cell; } font, label, shadowColor, Accessory...

셀의 재사용

unselectCell // Respond to user selection - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath { NsIndexPath *idxPath = [self.tableView indexPathForSelectedRow] [self.tableView deselectRowAtIndexPath:idxPath animated:YES]; // 또는 [self.tableView deselectRowAtIndexPath:newIndexPath animated:YES]; }

테이블 셀 (Cell) Figure 5-1 Parts of a table-view cell Figure 5-2 Parts of a table-view cell—editing mode

테이블 셀 (Cell) Figure 1-6 Default table row style (no subtitle) Figure 1-7 Table row style with subtitle under title UITableViewCellStyleSubtitle

테이블 셀 (Cell) Figure 1-8 Table row style with right-aligned subtitle Figure 1-9 Table row style in Contacts format UITableViewCellStyleValue2UITableViewCellStyleValue1

테이블 셀 (Cell) Initializing a UITableViewCell Object – initWithStyle:reuseIdentifier: – initWithFrame:reuseIdentifier: Deprecated in iOS 3.0 Reusing Cells reuseIdentifier property – prepareForReuse Managing Text as Cell Content textLabel property detailTextLabel property font property Deprecated in iOS 3.0 lineBreakMode property Deprecated in iOS 3.0 selectedTextColor property Deprecated in iOS 3.0 text property Deprecated in iOS 3.0 textAlignment property Deprecated in iOS 3.0 textColor property Deprecated in iOS 3.0 Managing Images as Cell Content imageView property image property Deprecated in iOS 3.0 selectedImage property Deprecated in iOS 3.0

테이블 셀 (Cell) Accessing Views of the Cell Object contentView property backgroundView property selectedBackgroundView property Managing Accessory Views accessoryType property accessoryView property editingAccessoryType property editingAccessoryView property hidesAccessoryWhenEditing property Deprecated in iOS 3.0 Managing Cell Selection and Highlighting selected property selectionStyle property – setSelected:animated: highlighted property – setHighlighted:animated:

Customizing Cells add subviews to the contentView property of the cell object or you can create a custom subclass of UITableViewCell

Customizing Cells #define MAINLABEL_TAG 1 #define SECONDLABEL_TAG 2 #define PHOTO_TAG 3 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier UILabel *mainLabel, *secondLabel; UIImageView *photo; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)] autorelease]; mainLabel.tag = MAINLABEL_TAG; mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:mainLabel]; secondLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 20.0, 220.0, 25.0)] autorelease]; secondLabel.tag = SECONDLABEL_TAG; secondLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:secondLabel]; photo = [[[UIImageView alloc] initWithFrame:CGRectMake(225.0, 0.0, 80.0, 45.0)] autorelease]; photo.tag = PHOTO_TAG; photo.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:photo];

Customizing Cells } else { mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG]; secondLabel = (UILabel *)[cell.contentView viewWithTag:SECONDLABEL_TAG]; photo = (UIImageView *)[cell.contentView viewWithTag:PHOTO_TAG]; } NSDictionary *aDict = [self.list objectAtIndex:indexPath.row]; mainLabel.text = [aDict secondLabel.text = [aDict NSString *imagePath = [[NSBundle mainBundle] pathForResource:[aDict UIImage *theImage = [UIImage imageWithContentsOfFile:imagePath]; photo.image = theImage; return cell; }

악세사리 ( 다중선택 구현 ) if (cell.accessoryType == UITableViewCellAccessoryNone) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } accessoryType = UITableViewCellAccessoryNone; // DisclosureIndicator, DetailDisclosure, Checkmark

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Recover the cell and key UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; NSString *key = cell.textLabel.text; // Created an inverted value and store it BOOL isChecked = !([[self.stateDictionary objectForKey:key] boolValue]); NSNumber *checked = [NSNumber numberWithBool:isChecked]; [self.stateDictionary setObject:checked forKey:key]; // Update the cell accessory checkmark cell.accessoryType = isChecked ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; } - (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath {cell.accessoryType = checked.boolValue ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;

- (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Retrieve or create a cell UITableViewCellStyle style = UITableViewCellStyleDefault; UITableViewCell *cell = [tView if (!cell) cell = [[[UITableViewCell alloc] initWithStyle:style autorelease]; // Set cell label NSString *key = " stringByAppendingString:[ALPHA objectAtIndex:indexPath.row]]; cell.textLabel.text = key; /* Used to create Figure if (indexPath.row % 2) cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; else cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; */ cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; cell.editingAccessoryType = UITableViewCellAccessoryNone; return cell; } // Respond to accessory button taps -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [[self navigationController] pushViewController:[ImageController newController] animated:YES]; }

edit / delete [self.tableView setEditing:YES animated:YES]; - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } [self.tableView reload]; UITableViewRowAnimationFade UITableViewRowAnimationRight UITableViewRowAnimationLeft UITableViewRowAnimationTop UITableViewRowAnimationButtom

reordering // Add the edit button self.navigationItem.rightBarButtonItem = self.editButtonItem; // Perform the re-order -(void) tableView: (UITableView *) tableView moveRowAtIndexPath: (NSIndexPath *) oldPath toIndexPath:(NSIndexPath *) newPath { NSString *title = [tableTitles objectAtIndex:[oldPath row]]; [tableTitles removeObjectAtIndex:[oldPath row]]; [tableTitles insertObject:title atIndex:[newPath row]]; } // Handle deletion - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { printf("About to delete item %d\n", [indexPath row]); [tableTitles removeObjectAtIndex:[indexPath row]]; [self.tableView reloadData]; }

sample 실습 파일 브라우저

응용 - Undo / Redo NSUndoManager *undoManager; [self.undoManager undo]; [self.undoManager redo]; [[self.undoManager prepareWithInvocationTarget:self] updateItemAtIndexPath:indexPath withString:undoString]; // called as: // [[undoManager prepareWithInvocationTarget:self] setFont:oldFont color:oldColor] // When undo is called, the specified target will be called with // [target setFont:oldFont color:oldColor]

sample 응용 SearchBar Header In Section Button in Header Change Bar Color

sample 응용 Grouped Table

테이블 뷰 컨트롤러 계층

Figure 3-3 Navigation controller and view controllers in a navigation-based application

sample 실습 UITabBarController 와 UINavigationCont roller 와 UITableViewConroller 를 함께 써보자

섹션 목록 p342

섹션 목록 생성 self = [super initWithStyle:UITableViewStyleGrouped]; // ---> self = [super init]; numberOfSectionsInTableView numberOfRowsInSection cellForRowAtIndexPath titleForHeaderInSection heightForRowAtIndexPath sectionIndexTitlesForTableView sectionForSectionIndexTitle

인덱스 바 추가 self = [super initWithStyle:UITableViewStyleGrouped]; // ---> self = [super init]; #define - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)aTableView { if (aTableView == self.tableView) // regular table { NSMutableArray *indices = [NSMutableArray arrayWithObject:UITableViewIndexSearch]; for (int i = 0; i < 26; i++) if ([[self.sectionArray objectAtIndex:i] count]) [indices addObject:[[ALPHA substringFromIndex:i] substringToIndex:1]]; return indices; } else return nil; // search table }

sample 실습 TableDemo: 더 나은 파일 브라우저

sample 응용

Core Location p272

CoreLocation Manager LocationController : UIViewController { CLLocationManager *manager; } delegate desiredAccuracy - kCLLocationAccuracyBest - kCLocationAccuracyNearestTenMeters - kCLLocationAccuracyHundredMeters - kCLLocationAccuracyKilometer - kCLocationAccuracyThreeKilometers distanceFilter - kCLDistanceFilterNone (all)

쿼리 생성 - (void) viewDidLoad { self.locManager = [[[CLLocationManager alloc] init] autorelease]; if (!self.locManager.locationServicesEnabled) { [self has opted out of location services"]; return; } self.locManager.delegate = self; self.locManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; [self.locManager startUpdatingLocation]; }

업데이트 정보 수신 경도 및 위도 | datatype : CLLocationDegrees 고도 | datatype : CLLocationDistance 정확도 | datatype: CLLocationAccuracy 타임스탬프 : datatype: NSDate - GPS 정확도가 향상 되거나 Filter 에 설정한 거리만큼 이동했을 때 주기적으로 전송됨 디스크립션 | datatype: NSString - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (newLocation.speed > 0.0f) { NSString *speedFeedback = [NSString is %0.1f miles per hour", * newLocation.speed]; [self report:speedFeedback]; [self doLog:speedFeedback]; }

업데이트 정보 수신 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { // test that the horizontal accuracy does not indicate an invalid measurement if (newLocation.horizontalAccuracy < 0) return; // test the age of the location measurement to determine if the measurement is cached // in most cases you will not want to rely on cached measurements NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow]; if (locationAge > 5.0) return; // store all of the measurements, just so we can see what kind of data we might receive [locationMeasurements addObject:newLocation]; // update the display with the new location data Coordinates:%f, %f”, newLocation.coordinate.latitude, newLocation.coordinate.longitude); }

쿼리 완성 - (void)stopUpdatingLocation:(NSString *)state { [locationManager stopUpdatingLocation]; locationManager.delegate = nil; } 오류 처리 - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { // The location "unknown" error simply means the manager is currently unable to get the location. if ([error code] != kCLErrorLocationUnknown) { } kCLErrorLocationUnkown kCLErrorDenied

Map p272

reverse geocoding 위도와 경도 정보를 사람이 이해하는 주소 정보로 변환하는 것

reverse geocoding - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate]; geocoder.delegate = self; [geocoder start]; } TestBedViewController : UIViewController

reverse geocoding - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { [placemark.addressDictionary description]]); if ([geocoder retainCount]) [geocoder release]; } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { [self geocoder error: [error description]]; }

코어로케이션 데이터를 사용한 지도 TestBedViewController : UIViewController { CLLocationManager *locManager; IBOutlet MKMapView *mapView; CLLocation *bestLocation; int timespent; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { // Keep track of the best location found if (!self.bestLocation) self.bestLocation = newLocation; else if (newLocation.horizontalAccuracy < bestLocation.horizontalAccuracy) self.bestLocation = newLocation; mapView.region = MKCoordinateRegionMake(self.bestLocation.coordinate, MKCoordinateSpanMake(0.1f, 0.1f)); mapView.showsUserLocation = YES; mapView.zoomEnabled = NO; }

코어로케이션 데이터를 사용한 지도 표현 if (mapView.userLocation) [mapView setRegion:MKCoordinateRegionMake(mapView.userLocation.location.coo rdinate, MKCoordinateSpanMake(0.005f, 0.005f)) animated:NO]; mapView.userLocation.title Coordinates"; mapView.userLocation.subtitle = [NSString %f", mapView.userLocation.location.coordinate.latitude, mapView.userLocation.location.coordinate.longitude]; mapView.showsUserLocation = YES;

코어로케이션 데이터를 사용한 지도 표현 MapAnnotation *annotation = [[[MapAnnotation alloc] initWithCoordinate:self.current.coordinate] autorelease]; self.current.coordinate.latitude, self.current.coordinate.longitude); annotation.title = CURRENT_STRING; MapAnnotation *a1 = [[[MapAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake( , )] autorelease]; a1.title a1.subtitle [annotations addObject:a1]; [annotations addObject:annotation];

코어로케이션 데이터를 사용한 지도 표현 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { MapAnnotation *annotation = view.annotation; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:annotation.subtitle]]; }

코어로케이션 데이터를 사용한 지도 표현 - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { // Initialize each view for (MKPinAnnotationView *mkaview in views) { // The current location does not get a button if ([mkaview.annotation.title isEqualToString:CURRENT_STRING]) { mkaview.pinColor = MKPinAnnotationColorPurple; mkaview.rightCalloutAccessoryView = nil; continue; } // All other locations are red with a button mkaview.pinColor = MKPinAnnotationColorRed; UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; mkaview.rightCalloutAccessoryView = button; }