ヒレガス本 第10章 アラート・パネル

NSRunAltertPanel()でモーダル・ダイアログを出すことができる。

演習問題はこんな感じ。switch case構文忘れてるし!

- (IBAction)deleteEmployee: (id)sender
{
	NSArray *a = [[tableView selectedRowEnumerator] allObjects];
	int i;
	int choice;

	if ([a count] == 0) return;
	choice = NSRunAlertPanel(@"Delete",
							 @"Do you really want to delete %d records?",
							 @"Yes", @"No", @"Keep, but no raise", [a count]);
	NSLog(@"deleteEmployee: choice %d", choice);
	switch(choice) {
	case NSAlertDefaultReturn:
		for (i = [a count] - 1; i >= 0; i--) {
			[employees removeObjectAtIndex: [[a objectAtIndex: i] intValue]];
			[self updateChangeCount: NSChangeDone];
		}
		[self updateUI];
		break;
	case NSAlertOtherReturn:
		for (i = [a count] - 1; i >= 0; i--) {
			[[employees objectAtIndex: [[a objectAtIndex: i] intValue]] setExpectedRaise: 0.0];
		}
		[self updateUI];
		break;
	}
}