我剛剛開始學習Objective-C和iOS開發,並且嘗試將iPhone應用程序遷移到iPad時遇到了一些麻煩。iOS SplitView/Universal需要xcode 4.2
我一直在閱讀Head First iPhone & iPad Development 2nd Edition,但第7章「遷移到iPad」已過期,因爲xcode 4.2已過期。 該應用程序演示瞭如何在表視圖和詳細視圖中使用拆分視圖。
將iOS應用程序目標從iPhone更改爲Universal時,它們具有自動創建的MainWindow-iPad.xib。但是這在xcode 4.2中並沒有發生。我已經在AppDelegate中以編程方式創建了一個splitview控制器。下面是代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
MasterViewController *firstVC = [[[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil] autorelease];
self.secondVC = [[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] autorelease];
UINavigationController *firstVCnav = [[[UINavigationController alloc] initWithRootViewController:firstVC] autorelease];
UINavigationController *secondVCnav = [[UINavigationController alloc] initWithRootViewController:self.secondVC];
UISplitViewController *splitVC = [[UISplitViewController alloc] init];
splitVC.viewControllers = [NSArray arrayWithObjects:firstVCnav, secondVCnav, nil];
self.window.rootViewController= splitVC;
[self.window makeKeyAndVisible];
return YES;
}else {
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
}
的SPLITVIEW(表視圖)的左側進行良好的,但我不能讓右側(詳細側),以改變當我選擇在不同行左邊。這是我在MasterViewController類中的代碼。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
AppDelegate *splitVCdetails = [[AppDelegate alloc] init];
[splitVCdetails.secondVC drinkChanged:[self.drinks objectAtIndex:indexPath.row]];
}else {
if (!self.editing) {
if (!self.detailViewController) {
self.detailViewController = [[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] autorelease];
}
self.detailViewController.drink = [self.drinks objectAtIndex:indexPath.row];
[self.navigationController pushViewController:self.detailViewController animated:YES];
}else {
AddDrinkViewController *editingDrinkVC = [[AddDrinkViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
editingDrinkVC.drink = [self.drinks objectAtIndex:indexPath.row];
editingDrinkVC.drinkArray = self.drinks;
UINavigationController *editingNavCon = [[UINavigationController alloc] initWithRootViewController:editingDrinkVC];
[self.navigationController presentModalViewController:editingNavCon animated:YES];
[editingDrinkVC release];
[editingNavCon release];
}
}
}
下面是代碼我在DetailViewController類
-(void)refreshView {
//Set up our UI with the provided drink
self.drinkTextLabel.text = [self.drink objectForKey:NAME_KEY];
self.ingredientTextBox.text = [self.drink objectForKey:INGREDIENTS_KEY];
self.directionTextBox.text = [self.drink objectForKey:DIRECTIONS_KEY];
}
-(void)drinkChanged:(NSDictionary *)newDrink {
self.drink = newDrink;
[self refreshView];
}
請讓我知道如果我需要澄清什麼。
謝謝