我在这里有这段代码:
if(isLocationTag == YES)
{
NSArray *isLocationTagArray = [self getLocationInfo:Name];
if(isLocationTagArray == nil)
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Message" message:@"There is an issue with the location tag." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];
[self presentViewController:alertController animated:YES completion:nil];
ScannerMessage.text = @"READY TO SCAN";
ScannerMessage.backgroundColor = [UIColor greenColor];
}
else
{
[self performSegueWithIdentifier: @"SegueIdentifier" sender: self];
}
}
我想要做的是推动NSArray isLocationTagArray与performSegueWithIdentifier
我添加了这个方法:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"SegueIdentifier"])
{
ListViewController *myVC = [segue destinationViewController];
}
}
但我如何通过NSArray?
答案 0 :(得分:2)
您必须在目标VC(ListViewController)中定义属性,然后在prepareForSegue中设置它。像这样:
ListViewController.h
@property (strong,nonatomic) NSArray* theParamenterArray;
然后在你的prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"SegueIdentifier"])
{
ListViewController *myVC = [segue destinationViewController];
myVC.theParamenterArray = isLocationTagArray;
}
}
这是您想要使用故事板在VC之间交换的所有数据的标准方式。
答案 1 :(得分:0)
使isLocationTagArray
成为模块级变量。然后向可以接受ListViewController
NSArray
添加媒体资源
然后你可以这样做
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"SegueIdentifier"])
{
ListViewController *myVC = [segue destinationViewController];
myVC.dataArray = isLocationTagArray
}
}
答案 2 :(得分:-1)
您可以将NSArray
作为发件人传递:
...
[self performSegueWithIdentifier: @"SegueIdentifier" sender: isLocationTagArray];
...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"SegueIdentifier"]) {
ListViewController *myVC = [segue destinationViewController];
if ([sender isKindOfClass: [NSArray class]]) {
myVC.dataArray = (NSArray *) sender;
}
}
}