2013-02-26 67 views
1

如何更新父视图,之后我关闭UIModalPresentationFormSheet视图。如果我使用普通视图,我可以重新加载我的父视图。仅在UIModalPresentationFormSheet中发布。请帮帮我。由于如何重载父视图

navigationController.modalPresentationStyle = UIModalPresentationFormSheet; 

如果我使用

navigationController.modalPresentationStyle = UIModalPresentationFullScreen; 

我可以刷新父tableview.Issue只在UIModalPresentationFormSheet,但我需要使用UIModalPresentationFormSheet为弹出的视图。请帮帮我。由于

+0

为什么要重新加载父视图? – 2013-02-26 06:48:36

+0

我在“UIModalPresentationFormSheet”视图中编辑一些数据。我想在父视图中显示更改。 – Suppry 2013-02-26 06:49:45

+2

你需要一些其他的通知的变化(KVO,NSNotificationCenter,委托传递引用和调用该方法,如此多的方式) – 2013-02-26 06:54:08

回答

3

IMO最简单的方法:在创建(或执行的SEGUE)的的FormController时

//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> 
... 

设置委托。
解雇时调用委托方法。 在MainViewController中实现委托方法。

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

如果我使用 navigationController.modalPresentationStyle = UIModalPresentationFullScreen; 我可以刷新只有在UIModalPresentationFormSheet父tableview.Issue,但我需要使用UIModalPresentationFormSheet为弹出的视图。请帮帮我。谢谢 – Suppry 2013-03-06 08:32:35

+0

完全相同。 – Mundi 2013-03-06 12:53:38

0

您应该委托PresentModalView的parentView,应该调用referesh方法上PresentModalView的viewWillDisappear。

否则,你可以尝试推送通知和parentView观察它。

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

//在ParentViewController - AddObserver中检测数据。 //和你想调用的方法。

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