[英]Load UIViewController on another UIViewController in UIStoryboard from xib
我有一個UIViewController(說A)。 一個單獨的nib文件被加載為該視圖控制器上的彈出窗口。 當通過單擊UIButton關閉彈出窗口時,我想在UIStoryBoard中加載另一個視圖控制器(說B)。 所有的UIViewControllers都在情節提要中。
我嘗試了代表模式。 委托方法將self.storyboard返回為nil 。
請建議如何處理(從A執行到B的候選,或者從nib文件在導航控制器上推送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給出nil值
請建議如何在SaveCustomViewNewPrescription中加載另一個視圖控制器。
代替:
RxViewController *obj1 = [[self.navigationController storyboard] instantiateViewControllerWithIdentifier:@"RxViewController"];
嘗試:
UIStoryboard *yourStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
RxViewController *obj1 = [yourStoryboard instantiateViewControllerWithIdentifier:@"RxViewController"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.