presentModalViewController 问题! [英] presentModalViewController Problem !

查看:91
本文介绍了presentModalViewController 问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,

我有一个表单(基本上是 UITableView),完成表单后,我单击屏幕顶部的完成"按钮.

I have a form (which is basically a UITableView), and once I finish the form, I click the 'Done' button which is on top of the screen.

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

After clicking, I need to add the data to another tableView (which is in another tableViewController). This table is also inside a Navigation Controller.

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

After I press the Done Button, I need the presentModalViewController to be the new TableView (with the new data) along with the Navigation Controller on top of the tableView.

总结一下:

  • 完成按钮位于 someTableViewController 中.
  • 我需要向另一个名为 dogTableViewController 的 tableView 添加一个对象(为了简单起见,我想添加一个名为Dobby"的名称).
  • 我重新加载数据,并显示在 dogNavigationController 中包含 dogTableViewController 的屏幕.
  • 所有类都被正确引用并包含在内.

我在点击完成按钮时粘贴 -(IBAction).

I am pasting the -(IBAction) when the Done Button is clicked.

-(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 屏幕上也有一些按钮.什么都看不见!!

I get an empty Navigation Screen with NO TABLE in it. Plus I also had some buttons on the dogNavigationController screen. Nothings visible !!

我的目标是将屏幕转移到这个新屏幕(恰好是主屏幕,而不是 rootController).你认为我应该使用 modalViewController 来完成这项任务吗?您认为我应该使用其他方式将数据传输到另一个屏幕吗?

My objective is to just transfer the screen to this new screen (which happens to be a home screen, and not the rootController). Do you think I should go with the modalViewController for this task ? Do you think I should use some other way to transfer data to another screen ?

附言我不想使用 PushViewController.

p.s. I do not want to use PushViewController.

推荐答案

我认为你应该这样做

[self.navigationController popToRootViewControllerAnimated:YES];

而是.要获取根视图控制器,您可以这样做,

rather. To get the root view controller, you can do,

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

原答案

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

Shouldn't you be initializing a navigation controller with the root view controller?

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

这篇关于presentModalViewController 问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆