1

所以,presentModalViewController問題!

我有一個表單(這基本上是一個UITableView),一旦我完成表單,我點擊屏幕頂部的'完成'按鈕。

點擊後,我需要將數據添加到另一個tableView(這是另一個tableViewController)。該表格也位於導航控制器內。

當我按下完成按鈕後,我需要將presentModalViewController作爲新的TableView(帶有新數據)以及位於tableView頂部的導航控制器。

因此,要總結:

  • 完成按鈕是someTableViewController。
  • 我需要添加一個對象(爲了簡單起見,我只是說我添加了一個名爲「Dobby」的名稱)到另一個名爲dogTableViewController的tableView中。
  • 我重新加載數據,並在dogNavigationController中顯示具有dogTableViewController的屏幕。
  • 所有的類都被正確引用幷包含在內。

我點擊完成按鈕時正在粘貼 - (IBAction)。

-(IBAction) doneWithData: (UIBarButtonItem*) sender{ 


UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; 
[indicator sizeToFit]; 
indicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | 
           UIViewAutoresizingFlexibleRightMargin | 
           UIViewAutoresizingFlexibleTopMargin | 
           UIViewAutoresizingFlexibleBottomMargin); 

indicator.tag = 1; 
[self.view addSubview:indicator]; 
[indicator setBackgroundColor:[UIColor clearColor]]; 
indicator.center = self.view.center; 
indicator.hidden = FALSE; 
[indicator startAnimating]; 

if (self.dogTableViewController == nil) 
{ 
    DogTableViewController *temp = [[DogTableViewController alloc] init]; 
    self.dogTableViewController = temp; 
    [temp release]; 
} 

if (self.dogNavigationController == nil) 
{ 
    DogNavigationController *temp = [[DogNavigationController alloc] init]; 
    self.dogNavigationController = temp; 
    [temp release]; 
} 

[self.dogTableViewController.dogArray addObject:@"Dobby"]; 
[self.dogTableViewController.tableView reloadData]; 

NSLog (@"%@", [self.dogTableViewController.dogArray objectAtIndex:0]); 
//Prints out "Null" // 

[self presentModalViewController:dogNavigationController animated:YES]; 


[indicator release]; 

} 

當我做了這一切,並單擊完成按鈕,

我與它沒有表空導航畫面。另外我還在dogNavigationController屏幕上有一些按鈕。沒什麼可見的!

我的目標是將屏幕轉移到這個新屏幕(恰好是主屏幕,而不是rootController)。你認爲我應該用modalViewController來完成這個任務嗎?你認爲我應該用其他方式將數據傳輸到另一個屏幕嗎?

p.s.我不想使用PushViewController。

+0

主屏幕?你不應該彈出嗎? – 2011-06-08 15:52:35

+0

這是應用程序的工作方式... 1 - > 2 - > 3-> 4-> 1 – Legolas 2011-06-08 15:55:27

+0

我點擊完成按鈕4,我需要1顯示添加的數據。 – Legolas 2011-06-08 15:55:59

回答

2

我認爲你應該做

[self.navigationController popToRootViewControllerAnimated:YES]; 

相當。爲了得到根視圖控制器,你可以做,

DogTableViewController * viewController = [self.navigationController.viewControllers objectAtIndex:0]; 
[viewController.dogArray addObject:aDog]; 

原來的答案

你不是應該用初始化根視圖控制器導航控制器?

DogNavigationController *temp = [[DogNavigationController alloc] initWithRootViewController:self.dogTableViewController]; 
+0

rootController是一個TabBarController – Legolas 2011-06-08 15:52:01

+0

所以我改變了上面發佈的代碼。我現在可以看到dogNavigationController的正確標題。我沒有看到任何UIBarButtonItem,我沒有看到tableView。 – Legolas 2011-06-08 15:54:23

+0

更新我的答案btw。 – 2011-06-08 16:01:53

相關問題