Suppry
Suppry

Reputation: 81

How to reload parent view

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

Upvotes: 1

Views: 2460

Answers (2)

Burcu Geneci
Burcu Geneci

Reputation: 85

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"]);    
    }

Upvotes: 0

Mundi
Mundi

Reputation: 80265

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]; 
}

Upvotes: 3

Related Questions