2013-08-07 60 views
0

我有一個UIViewController(說A)。在此視圖控制器上彈出一個單獨的nib文件。當通過單擊UIButton關閉彈出窗口時,我想在UIStoryBoard中加載另一個視圖控制器(說B)。所有的UIViewControllers都在storyboard中。加載UIViewController UIStoryboard從另一個UIViewController從xib

我試着用代表模式。委託方法返回self.storyboard爲

請建議如何處理(無論是performsegue從A到B或從筆尖文件導航控制器上推B的新實例)

這裏是我用於委託代碼:

**In CustomViewNewPrescription.h file:** 

    @class CustomViewNewPrescription; 
    @protocol CustomViewNewPrescriptionDelegate <NSObject> 
    -(void)SaveCustomViewNewPrescription; 
    @end 
    @interface CustomViewNewPrescription : UIView{ 
     id<CustomViewNewPrescriptionDelegate>delegate; 

    } 

    @property(nonatomic,strong) id<CustomViewNewPrescriptionDelegate>delegate; 

    **in .m:** 
    - (IBAction)btnCancel:(UIButton *)sender{ 
     [self.delegate SaveCustomViewNewPrescription]; 
    } 

delegate was synthesized and initialised. 

**In AddNewRx.h:** 
@interface AddNewRx : UIViewController<CustomViewNewPrescriptionDelegate>{ 
} 

**in AddNewRx.m:** 

-(void)SaveCustomViewNewPrescription{ 
    //either self performseguewithidentifier .... (or) 
    RxViewController *obj1 = [[self.navigationController storyboard] instantiateViewControllerWithIdentifier:@"RxViewController"]; 
    [self.navigationController pushViewController:obj1 animated:YES]; 
} 

在SaveCustomViewNewPrescription ,self.storyboard給出零值

請建議如何在SaveCustomViewNewPrescription中加載另一個視圖控制器。

回答

1

相反的:

RxViewController *obj1 = [[self.navigationController storyboard] instantiateViewControllerWithIdentifier:@"RxViewController"]; 

嘗試:

UIStoryboard *yourStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
RxViewController *obj1 = [yourStoryboard instantiateViewControllerWithIdentifier:@"RxViewController"]; 
相關問題