1

所以,

我有一个表单(基本上是一个 UITableView),一旦我完成表单,我点击屏幕顶部的“完成”按钮。

点击后,我需要将数据添加到另一个tableView(在另一个tableViewController中)。该表也在导航控制器内。

按下完成按钮后,我需要 presentModalViewController 成为新的 TableView(带有新数据)以及位于 tableView 顶部的导航控制器。

所以,总结一下:

  • 完成按钮位于 someTableViewController 中。
  • 我需要在另一个名为 dogTableViewController 的 tableView 中添加一个对象(为了简单起见,我只是说我正在添加一个名为“Dobby”的名称)。
  • 我重新加载数据,并在 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 来完成这项任务吗?您认为我应该使用其他方式将数据传输到另一个屏幕吗?

ps 我不想使用 PushViewController。

4

1 回答 1

2

我认为你应该这样做

[self.navigationController popToRootViewControllerAnimated:YES];

相当。要获取根视图控制器,您可以这样做,

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

原始答案

您不应该使用根视图控制器初始化导航控制器吗?

DogNavigationController *temp = [[DogNavigationController alloc] initWithRootViewController:self.dogTableViewController];
于 2011-06-08T15:51:19.990 回答