2013-02-26 46 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"]);  
    }