1

How to update parent view, after i close the UIModalPresentationFormSheet view. If I use normal view I can reload my parent view. Issue only in UIModalPresentationFormSheet. Please help me. Thanks

 navigationController.modalPresentationStyle  = UIModalPresentationFormSheet;

If I use

navigationController.modalPresentationStyle  = UIModalPresentationFullScreen;

I can refresh the parent tableview.Issue only in UIModalPresentationFormSheet but I need to use UIModalPresentationFormSheet for popup view. Please help me. Thanks

Suppry
  • 81
  • 1
  • 9
  • why you want to reload the parent view? – Bryan Chen Feb 26 '13 at 06:48
  • I edit some data in "UIModalPresentationFormSheet" view. I want to show the changes in parent view. – Suppry Feb 26 '13 at 06:49
  • 2
    you need some other to notify the change (KVO, NSNotificationCenter, delegate, pass a reference and call the method, so many way) – Bryan Chen Feb 26 '13 at 06:54
  • @Joshy Joseph .... exactly so many ways are there wat he(@xlc0212) told .... – Nag_iphone Feb 26 '13 at 07:16
  • I think the easiest method is to reload in 'viewWillAppear'. After you dismiss the form sheet your previous controller in the navigation controller will get 'viewWillAppear' called. – George Feb 26 '13 at 07:55
  • @George Unfortunately not. The form is above the view and the view remains visible. So `viewWillAppear` is not called. – Mundi Feb 26 '13 at 09:21
  • Then..use delegation. I always use deletion for stuff like this but I thought 'viewWillAppear' would be easier. Just declare a protocol and a delegate property , set it and call the method in the protocol at the appropriate time. – George Feb 26 '13 at 09:35
  • Ok I will try delegation – Suppry Feb 26 '13 at 09:47
  • viewWillAppear and viewDidLoad are not called when a view is re-displayed. See my answer at http://stackoverflow.com/a/18493699/1532399 – tooluser Aug 28 '13 at 16:45

2 Answers2

3

IMO easiest way:

//FormController.h

@protocol FormDelegate;

@interface FormController : UIViewController 
...
@property (nonatomic, assign) id <FormDelegate> delegate;
...
@end

@protocol FormDelegate
-(void)didDismissForm;
@end

//MainViewController.h

#import "FormController.h"    
@interface MainViewController : UIViewController <FormDelegate>
...

Set the delegate when creating (or performing segue of) the FormController.
Call the delegate method when you dismiss it. Implement the delegate method in the MainViewController.

-(void)didDismissForm {
   [self.tableView reloadData]; 
}
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • If I use navigationController.modalPresentationStyle = UIModalPresentationFullScreen; I can refresh the parent tableview.Issue only in UIModalPresentationFormSheet but I need to use UIModalPresentationFormSheet for popup view. Please help me. Thanks – Suppry Mar 06 '13 at 08:32
  • Works exactly the same way. – Mundi Mar 06 '13 at 12:53
0

You should delegate the parentView of PresentModalView and should call referesh method on the viewWillDisappear of PresentModalView.

Otherwise, you can try to push notification and observe it in parentView.

    - (void) refreshMyParentViewController{
     NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
     [center postNotificationName:@"RefreshNeeded" object:self userInfo:refreshData];
}

//In ParentViewController -- AddObserver to detect data. // And the method you want to call.

[[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(delegateMethod:) 
                                                 name:@"RefreshNeeded" object:nil];

- (void)delegateMethod:(NSNotification *)notification {
      NSLog(@"%@", notification.userInfo);
      NSLog(@"%@", [notification.userInfo objectForKey:@"RefreshObject"]);    
}



   [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(delegateMethod:) 
                                                     name:@"RefreshNeeded" object:nil];

    - (void)delegateMethod:(NSNotification *)notification {
          NSLog(@"%@", notification.userInfo);
          NSLog(@"%@", [notification.userInfo objectForKey:@"RefreshObject"]);    
    }