storyboard跳转时传数据

我们做iOS开发是一定会有很多的页面跳转,用代码写是不是很烦呢,特别使我们已经了解storyboard的方便,但有时候跳转是必要的要向下一个页面传送很多数据,所以我们又不得不用代码写,这是一个问题。

解决:- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

这个方法是使用storyboard连线跳转是触发的其中参数segue表示我们跳转连的那根线,他有几个属性:@property (nonatomic, readonly) NSString *identifier;                 唯一标识,用于好几个线一起时,区分谁是谁。

@property (nonatomic, readonly) id sourceViewController;          原页面,就是线的开始端

@property (nonatomic, readonly) id destinationViewController;    跳转页面, 线的结束段

补:identifier的值可以在storyboard上点击线编辑

使用实例:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"segueInformation"]) {

}

if ([segue.identifier isEqualToString:@"shoppingcartDe"]) { //判断是那条线

BMCLSingleDetailsViewController *vc = segue.destinationViewController;//找到目的页面,有目的页面就可以随意传数据了不是吗?

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;

}];

}

你可能感兴趣的:(storyboard跳转时传数据)