我正在使用这个函数在 Xcode 4.3 中切换视图。
[self performSegueWithIdentifier:@"NextView" sender:self];
我想在页面之间传递一些参数,我应该如何做到这一点?
我正在使用这个函数在 Xcode 4.3 中切换视图。
[self performSegueWithIdentifier:@"NextView" sender:self];
我想在页面之间传递一些参数,我应该如何做到这一点?
performSegueWithIdentifier:sender:
执行后,您的视图控制器会调用
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
假设您的新视图控制器有一些属性需要设置:
if ([[segue identifier] isEqualToString:@"NextView"]) {
MyViewController *myVC = [segue destinationViewController];
myVC.propertyToSet = // set your properties here
}
[myVC setProperty1:self.property1 viewTitle:@"My Title" delegate:self];
。 - johnnyspoIn your destinationViewController.h file add property setting for variable to 'receive' value from your source controller.m file
@property (nonatomic) int billIdReceivingVote;
Import your destinationViewController.h to your sourceViewController.m file:
// VOLViewController.m
#import "VOLVoteViewController.h
Add prepareForSegue
method to your sourceViewController.m file and pass the variables
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
VOLVoteViewController *myDestinationViewController = [segue destinationViewController];
// myDestinationViewController.variable = sourceViewController variabe
myDestinationViewController.billIdReceivingVote = [self.idOfBillSelected intValue];
}