我們做iOS開發(fā)是一定會有很多的頁面跳轉(zhuǎn)蹋笼,用代碼寫是不是很煩呢萧锉,特別使我們已經(jīng)了解storyboard的方便溺欧,但有時候跳轉(zhuǎn)是必要的要向下一個頁面?zhèn)魉秃芏鄶?shù)據(jù)暑认,所以我們又不得不用代碼寫,這是一個問題辜限。
解決:- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
這個方法是使用storyboard連線跳轉(zhuǎn)是觸發(fā)的其中參數(shù)segue表示我們跳轉(zhuǎn)連的那根線皇拣,他有幾個屬性:@property (nonatomic, readonly) NSString *identifier; ??????????????? 唯一標(biāo)識,用于好幾個線一起時薄嫡,區(qū)分誰是誰氧急。
@property (nonatomic, readonly) id sourceViewController;????????? 原頁面,就是線的開始端
@property (nonatomic, readonly) id destinationViewController;??? 跳轉(zhuǎn)頁面毫深, 線的結(jié)束段
補(bǔ):identifier的值可以在storyboard上點(diǎn)擊線編輯
使用實(shí)例:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"segueInformation"]) {
}
if ([segue.identifier isEqualToString:@"shoppingcartDe"]) { //判斷是那條線
BMCLSingleDetailsViewController *vc = segue.destinationViewController;//找到目的頁面吩坝,有目的頁面就可以隨意傳數(shù)據(jù)了不是嗎?
vc.shopId=sender;
}
if ([segue.identifier isEqualToString:@"segueDJJ"]) {
NSString *strID=@"";
for (GeneralMode *mode in _arrDataSoucre) {
strID= [strID stringByAppendingString:@","];
strID= [strID stringByAppendingString:mode.ID];
strID= [strID stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
}
BMCLVoucherViewController *vc=segue.destinationViewController;
vc.strGoodIDlist=strID;
[vc setBlockBackpric:^(CGFloat pric,NSString *strIdDJJ) {
_labDJJPirc.text=[NSString stringWithFormat:@"-¥%.2f",pric];
_strIdDJJ=strIdDJJ;
[self setMoney:pric];
}];
}
if ([segue.identifier isEqualToString:@"segueQDaddress"]) {
if (_modeAddress.ID.length == 0) {
BMVLAddAddressViewController * vc = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([BMVLAddAddressViewController class])];
[self.navigationController pushViewController:vc animated:YES];
}else{
BMCLMyaddressViewController *vc=segue.destinationViewController;
vc.shoppingSign=@"123456";
vc.orderSIgn=_modeAddress.ID;
vc.blockShoopingChart=^(GeneralMode *mode){
_defaultTips.hidden=YES;
_labArea.text=[NSString stringWithFormat:@"%@ %@ %@",mode.provinceid,mode.cityid,mode.districtid];
_labDetlAddress.text=mode.detail;
_labNameAndPostCode.text=[NSString stringWithFormat:@"%@ %@",mode.nick_name,mode.post_code];
_labPhone.text=mode.receiver_phone;
_modeAddress=mode ;
};
vc.blockDel=^(NSString *str){
_defaultTips.hidden=NO;
_labArea.text=@"";
_labDetlAddress.text=@"";
_labNameAndPostCode.text=@"";
_labPhone.text=@"";
_modeAddress=nil;
};
}
}
if ([segue.identifier isEqualToString:@"segueQRFP"]) {
BMCLInvoiceViewController *vc=segue.destinationViewController;
[vc setBlockBackInfo:^(GeneralMode *modeFP) {
_modeFP=modeFP;
_labFPType.text=modeFP.strType;
}];
}