storyboard跳轉(zhuǎn)時傳數(shù)據(jù)

我們做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; ??????????????? 唯一標識,用于好幾個線一起時,區(qū)分誰是誰。

@property (nonatomic, readonly) id sourceViewController;????????? 原頁面,就是線的開始端

@property (nonatomic, readonly) id destinationViewController;??? 跳轉(zhuǎn)頁面, 線的結(jié)束段

補:identifier的值可以在storyboard上點擊線編輯

使用實例:

- (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;

}];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容