Ios 目标-C-带performSegueWithIdentifier的推送NSArray
我这里有一段代码:Ios 目标-C-带performSegueWithIdentifier的推送NSArray,ios,objective-c,Ios,Objective C,我这里有一段代码: if(isLocationTag == YES) { NSArray *isLocationTagArray = [self getLocationInfo:Name]; if(isLocationTagArray == nil) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle
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];
}
}
我要做的是用performsguewithidentifier
我添加了以下方法:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"SegueIdentifier"])
{
ListViewController *myVC = [segue destinationViewController];
}
}
但是如何传递NSArray?将
isLocationTagArray
设置为模块级变量。然后将一个属性添加到您的ListViewController
,该属性可以接受NSArray
那你就可以这么做了
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"SegueIdentifier"])
{
ListViewController *myVC = [segue destinationViewController];
myVC.dataArray = isLocationTagArray
}
}
您必须在目标VC(ListViewController)中定义一个属性,然后在prepareForSegue中进行设置。大概是这样的: ListViewController.h
@property (strong,nonatomic) NSArray* theParamenterArray;
然后在你的准备格中:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"SegueIdentifier"])
{
ListViewController *myVC = [segue destinationViewController];
myVC.theParamenterArray = isLocationTagArray;
}
}
这是使用脚本在VCs之间交换所有数据的标准方式。您可以将您的
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;
}
}
}