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

> Head First iPhone Development #4

Chapter 4. multiple views - A table with a view

The title of the main view
Setting the title for the main view of the app means that additional views will automatically have back buttons to get to the main view.

Display drink list
  1. Declare the drink array. (.h file)
    • NSMutableArray* drinks;
    • @property ~
    • @synthesize ~
  2. Implement and populate the array. (viewDidLoad method at .m file)
    • NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithObjects:@"Firecracker", @"Lemon Drop", @"Mojito", nil];
  3. Tell the table how many rows you have. (numberOfRowsInSection method at .m file)
    • return [self.drinks count];
  4. Populate the table cells. (cellForRowAtIndexPath method at .m file)
    • cell.textLabel.text = [self.drinks objectAtIndex:indexPath.row];

Variable allocation

// 1st Method : Book

NSMutableArray* tmpArray = [[NSMutableArray allocinitWithObjects:@"Firecracker"@"Lemon Drop"@"Mojito"nil];

self.drinks = tmpArray;

[tmpArray release];

// 2nd Method : MissFlash

self.drinks = [[NSMutableArray allocinitWithObjects:@"Firecracker"@"Lemon Drop"@"Mojito"nil];

// 3rd Method : Book

NSString* path = [[NSBundle mainBundlepathForResource:@"DrinkArray" ofType:@"plist"];

NSMutableArray *tmpArray = [[NSMutableArray allocinitWithContentsOfFile:path];

self.drinks = tmpArray;

[tmpArray release];

Use the navigation controller to switch between views
  • A view stack for moving between views
  • A navigation bar for buttons and a title
  • A navigation toolbar for view-specific buttons

Navigation controllers maintain a stack of views
  • Use the tap notification in the table view delegate
  • tableview:didSelectRowAtIndexPath

Instantiate a view controller like any other class
  • [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];
  • At RootViewController.m

#import "DrinkDetailViewController.h"


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    DrinkDetailViewController *drinkDetailViewController = [[DrinkDetailViewController allocinitWithNibName:@"DrinkDetailViewController" bundle:nil];

    [self.navigationController pushViewController:drinkDetailViewController animated:YES];

    [drinkDetailViewController release];


Create a back button
When you added a title for the main view, the navigation controller kept track of that name as part of the view stack for navigation, and added a back button with the title in it automatically.

Debug process
  1. First stop on your debugging adventure: the console (Run -> Console)
  2. Interact with your application while it's running
  3. And when it's about to stop running
  4. Xcode supports you after your app breaks, too
  5. The Xcode debugger shows you the state of your application (Shift-Commander-Y key)

아이패드 국내 출시를 기원합니다. :-)
Steve Jobs for Fortune magazine
Steve Jobs for Fortune magazine by tsevis 저작자 표시비영리변경 금지

이 글은 새로운 정보가 추가될 때마다 업데이트됩니다. 추천으로 아래 숫자에 1을 더해보세요. :)
RSS구독을 하시면 포스트를 배달해 드립니다. ▷ 한RSS 구독하기, 구글리더 구독하기

댓글을 달아 주세요