保存数据后如何呈现detailview

时间:2012-09-29 12:40:50

标签: iphone objective-c ios uinavigationcontroller

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

目前, 我使用的是NavigationController,它是Master(UITableView) - > Detail(UITextView),因此用户可以添加数据并保存到sqLite,并在保存表单中的数据后,表单被解除并显示MasterView。

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

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 presentViewController:navContainer animated:YES completion:nil];
  [addFormController release];
}

AddFormController.m

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

感谢。

2 个答案:

答案 0 :(得分:1)

您可以在DetailViewController的{​​{1}}中展示自己的MasterViewController

但是,由于您不希望每次都发生这种情况(例如,在启动应用程序时显示viewDidAppear),您希望在{{1}中设置类似DetailViewController的布尔属性标记仅当标志为dataSaved时才执行我的第一段。您可以将标记设置为MasterViewController YES。怎么做?有几种方法,但我会使用委托。

一旦您从YES出示[AddFormController saveTemplate],请不要忘记取消设置标记。

答案 1 :(得分: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.