3

I am calling a settings page as a form sheet over a viewController using the following code:

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *device = [standardUserDefaults objectForKey:@"Device"];
if ([device isEqualToString:@"iPhone"]) {
    Settings_iPhone *screen = [[Settings_iPhone alloc] initWithNibName:nil bundle:nil];
    screen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:screen animated:YES];
    [screen release];
}
if ([device isEqualToString:@"iPad"]) {    
    Settings_iPhone *screen = [[Settings_iPhone alloc] initWithNibName:@"Settings_iPad" bundle:nil];
    screen.modalPresentationStyle = UIModalPresentationFormSheet;
    screen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:screen animated:YES];
    [screen release];
}

When the settings page is called and dismissed, viewDidAppear and viewWillAppear are not called on the original page only on the iPad. On the iPhone, since its not a formsheet, it works perfectly, and furthermore when I call the settings page on the iPad as a regular modal view instead of a form sheet, they both get called. Please help. Thanks!

Prajoth
  • 870
  • 3
  • 12
  • 25
  • Well you can use the delegate to accomplish your task which you wanted to do in your viewDidAppear/viewWillAppear. or else look at http://useyourloaf.com/blog/2010/5/3/ipad-modal-view-controllers.html to understand complete scenario how ModalViewController works. – Praveen-K May 22 '12 at 18:31
  • basically, if the settings updates any values, I need those values to be updated on the screen, so how would I be able to do that? – Prajoth May 22 '12 at 18:41
  • and there is no way to do this using viewDidAppear? i have to use notifications? – Prajoth May 22 '12 at 19:18
  • I will suggest you to use delegate. – Praveen-K May 22 '12 at 19:45
  • Can you please tell me how to implement that? – Prajoth May 22 '12 at 20:33
  • first you must have to fetch value from NSUserDefault on setting view page. thats is first it is nil values from NSUserDefault because right now no changes in setting page..after any changes save you changes in NSUserDefault before view will dismiss..may it will help you –  Dec 23 '13 at 07:21

1 Answers1

0

You can pass the value of the parent view controller to the modal view before presenting it (just add a property and keep the reference). When you're done in your modal view, call a method on the parent (in this one you can pass whatever that is needed to be passed to the parent view -(void)imDone:(NSObject yourValue) and call the dismiss on the Parent (dismissViewController:Animated:).

You can use this approach on both iPhone and iPad.

I hope it helps.

P. Sami
  • 1,885
  • 2
  • 17
  • 37