简体   繁体   English

如何重新加载父视图

[英]How to reload parent view

How to update parent view, after i close the UIModalPresentationFormSheet view. 关闭UIModalPresentationFormSheet视图后,如何更新父视图。 If I use normal view I can reload my parent view. 如果我使用普通视图,我可以重新加载我的父视图。 Issue only in UIModalPresentationFormSheet . 仅在UIModalPresentationFormSheetUIModalPresentationFormSheet 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. 我可以刷新父tableview.Issue只在UIModalPresentationFormSheet但我需要使用UIModalPresentationFormSheet弹出视图。 Please help me. 请帮我。 Thanks 谢谢

IMO easiest way: IMO最简单的方法:

//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. 在创建(或执行segue)FormController时设置委托。
Call the delegate method when you dismiss it. 解雇时调用委托方法。 Implement the delegate method in the MainViewController. 在MainViewController中实现委托方法。

-(void)didDismissForm {
   [self.tableView reloadData]; 
}

You should delegate the parentView of PresentModalView and should call referesh method on the viewWillDisappear of PresentModalView. 您应该委托PresentModalView的parentView,并应该在PresentModalView的viewWillDisappear上调用referesh方法。

Otherwise, you can try to push notification and observe it in parentView. 否则,您可以尝试在parentView中推送通知并观察它。

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

//In ParentViewController -- AddObserver to detect data. //在ParentViewController中 - AddObserver来检测数据。 // 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"]);    
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM