0

从 presentViewController 保存数据后,是否可以自动转到 detailView。

目前,我使用的是 Master (UITableView) ->Detail (UITextView) 的 NavigationController,因此用户可以添加数据并保存到 sqLite,从表单中保存数据后,表单被关闭并出现 MasterView。

我想要的是,在保存数据后,表单被关闭并自动转到 DetailView 而不是 MasterView。

主视图控制器.m

- (void)addNew{
  AddFormController *addFormController = [[AddFormController alloc]
                                        initWithNibName:@"AddFormView" bundle:nil];
  UINavigationController* navContainer = [[UINavigationController alloc] initWithRootViewController:addFormController];
  [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Header-Blank.png"] forBarMetrics:UIBarMetricsDefault];
  [[UIApplication sharedApplication] setStatusBarHidden:YES];
  [self.navigationController presentViewController:navContainer animated:YES completion:nil];
  [addFormController release];
}

添加表单控制器.m

 - (IBAction) saveTemplate {
   .... // Saving data onto Sqlite
   [self dismissViewControllerAnimated:YES completion:nil];
 }

谢谢。

4

2 回答 2

1

您可以展示您DetailViewControllerMasterViewController.viewDidAppear

但是,由于您不希望每次都发生这种情况(例如,DetailViewController在应用程序启动时显示),您希望设置一个布尔属性标志,如dataSavedinMasterViewController并仅在标志为YES. 您可以将标志设置为YESfrom [AddFormController saveTemplate]。怎么做?有几种方法,但我会使用委托。

并且不要忘记在提交DetailViewControllerfrom后取消设置标志viewDidAppear

于 2012-09-29T14:14:46.153 回答
0
I think you should use this code.It is simpler than above.

Masterviewcontroller.m
- (void)addNew{
  AddFormController *addFormController = [[AddFormController alloc]
                                        initWithNibName:@"AddFormView" bundle:nil];
  UINavigationController* navContainer = [[UINavigationController alloc] initWithRootViewController:addFormController];
  [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Header-Blank.png"] forBarMetrics:UIBarMetricsDefault];
  [[UIApplication sharedApplication] setStatusBarHidden:YES];
 [self.navigationController pushViewController:rvc animated:YES];
  [addFormController release];
}

AddFormController.m

 - (IBAction) saveTemplate {
   .... // Saving data onto Sqlite
   [self.navigationController popViewControllerAnimated:YES];
 }

I think it will work better.
于 2012-09-29T17:21:11.687 回答