2012-10-30 22 views
2

我正在開發一些使用UIKit元素和xib文件的應用程序。首先,我創建了包含表格和詳細視圖的主細節應用程序。我已經定製了細胞和細節視圖,並且一切都很好。然後,我想添加一個新視圖,它將表現得像用戶將看到的第一個視圖。我創建了新視圖,然後想將它添加到應用程序委託中,就像添加了主視圖一樣。它的工作原理,但細節視圖不起作用,我不知道爲什麼。這裏有一些代碼可以使它更清晰。在創建較早的表後添加新的開始視圖 - 不起作用

的AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
[self customizeAppearance]; 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
HomeScreenViewController *homescr = [[HomeScreenViewController alloc]initWithNibName:@"HomeScreenViewController" bundle:nil]; 
self.navigationController = [[UINavigationController alloc] initWithRootViewController:homescr]; 
self.window.rootViewController = self.navigationController; 
[self.window makeKeyAndVisible]; 
return YES; 
} 

我的新的第一視圖上有一個按鈕:

- (IBAction)goToTableView:(id)sender { 
MasterViewController *tableView = [[MasterViewController alloc]initWithNibName:@"MasterViewController" bundle:nil]; 
[self presentViewController:tableView animated:YES completion:nil]; 
} 

它去masterViewController和顯示錶。然後我單擊表中的每個元素都沒有任何反應。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
NSLog(@"did select is up"); 
if (!self.detailViewController) { 
    self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
} 
NSDate *object2 = [array1 objectAtIndex:[indexPath row]]; 
self.detailViewController.detailItem = object2; 
[self.navigationController pushViewController:self.detailViewController animated:YES]; 
} 

的NSLog顯示的信息,但細節視圖不appear.Also的navigationController被顯示在第一圖,是沒有在表視圖中可見。

有人能告訴我我做錯了什麼嗎?

感謝提前:)

回答

2

你爲什麼不推在堆棧視圖的tableView,在goToTableView方法。這一切的變化之後應該工作:

- (IBAction)goToTableView:(id)sender { 
    MasterViewController *tableView = [[MasterViewController alloc]initWithNibName:@"MasterViewController" bundle:nil]; 
    [self.navigationController pushViewController:tableView animated:YES]; 
} 

欲瞭解更多信息請參見本主題:pushing on modal View

+0

太感謝你了,偉大工程! :]看起來像我需要修改基礎:) – repoguy

相關問題