Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning iOS5 Development.pdf
Скачиваний:
7
Добавлен:
09.05.2015
Размер:
15.6 Mб
Скачать

322

CHAPTER 9: Navigation Controllers and Table Views

Adding a Move Me Controller Instance

Now, we just need to add an instance of this new class to BIDFirstLevelController’s array of controllers. You’re probably comfortable doing this by now, but we’ll walk you through it just to keep you company.

In BIDFirstLevelController.m, import the new view’s header file by adding the following line of code just before the @implementation declaration:

#import "BIDMoveMeController.h"

Now, add the following code to the viewDidLoad method in the same file:

- (void)viewDidLoad { [super viewDidLoad];

self.title = @"First Level";

NSMutableArray *array = [[NSMutableArray alloc] init];

// Disclosure Button

BIDDisclosureButtonController *BIDDisclosureButtonController = [[BIDDisclosureButtonController alloc] initWithStyle:UITableViewStylePlain];

BIDDisclosureButtonController.title = @"Disclosure Buttons"; BIDDisclosureButtonController.rowImage = [UIImage

imageNamed:@"BIDDisclosureButtonControllerIcon.png"]; [array addObject:BIDDisclosureButtonController];

// Checklist

BIDCheckListController *checkListController = [[BIDCheckListController alloc] initWithStyle:UITableViewStylePlain];

checkListController.title = @"Check One"; checkListController.rowImage = [UIImage

imageNamed:@"checkmarkControllerIcon.png"]; [array addObject:checkListController];

// Table Row Controls

BIDRowControlsController *rowControlsController = [[BIDRowControlsController alloc] initWithStyle:UITableViewStylePlain];

rowControlsController.title = @"Row Controls"; rowControlsController.rowImage = [UIImage imageNamed:

@"rowControlsIcon.png"];

[array addObject:rowControlsController];

// Move Me

BIDMoveMeController *moveMeController = [[BIDMoveMeController alloc] initWithStyle:UITableViewStylePlain];

moveMeController.title = @"Move Me";

moveMeController.rowImage = [UIImage imageNamed:@"moveMeIcon.png"]; [array addObject:moveMeController];

self.controllers = array;

}

www.it-ebooks.info

CHAPTER 9: Navigation Controllers and Table Views

323

OK, let’s go ahead and compile this bad boy and see what shakes out. If everything went smoothly, our application will launch in the simulator with (count ‘em) four rows in the root-level table (see Figure 9–18). If you click the new one, called Move Me, you’ll go to a table whose rows make up a familiar childhood choosing rhyme (see Figure 9–6).

Figure 9–18. The Move Me row has been added to our table.

To reorder the rows, click the Move button in the upper-right corner, and the reorder controls should appear. If you tap a row’s reorder control and then drag, the row should move as you drag, as in Figure 9–6. Once you are happy with the row’s new position, release the drag. The row should settle into its new position nicely. You can even navigate back up to the top level and come back down, and your rows will be right where you left them. If you quit and return, they will be restored to their original order, but don’t worry; in a few chapters, we’ll show you how to save and restore data on a more permanent basis.

NOTE: If you find you have a bit of trouble making contact with the move control, don’t panic. This gesture actually requires a little patience. Try holding the mouse button clicked (if you’re in the simulator) or your finger pressed on the control (if you’re on a device) a bit longer before

moving it, in order to make the drag-to-reorder gesture work.

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]