2012-11-12 46 views
0
BookingDocumentsViewController *bdVc = [self.storyboard instantiateViewControllerWithIdentifier:@"BookingDocs"]; 
    bdVc.orId = rl_id; 
    bdVc.docsArray = self.documentsArray; 
    [self.navigationController pushViewController:bdVc animated:YES]; 

我有上面的代码片段。我试图加载新的视图 - 控制和可变数组(docsArray)对象分配给当前视图的mutableArray(documentsArray < =这不是零)ViewControllers之间传递MutableArray

每当我执行上面的代码中,我得到EXC_BAD_ACCESS错误。

,但如果我评论3号线。它的工作原理,但我不能让我的阵列到新的视图。我甚至尝试与[[NSMutableArray alloc] initWithArray:self.documentsArray];这也不工作。

但是,如果使用bdVc.docsArray =[[[NSMutableArray alloc] init];它的工作原理,但我又不能让我的可变数组新的观点。

编辑: 但是2号线有NSString的值。他们可以通过没有问题。

我在这里做错了什么?

我没有得到在控制台的任何错误,而不是我得到这个。

enter image description here

+0

后崩溃的堆栈跟踪。 – trojanfoe

+1

你在做bdVc的viewDidLoad或viewWillAppear/viewDidAppear中的docsArray吗? docsArray是一个强大的财产? – NikosM

+0

是的docsArray是一个强大的财产。而且我没有在docsArray中做任何其他事情。 – sleepwalkerfx

回答

0

我想我找到了问题。一个非常基本的错误。在bdVc的viewDidLoad我有以下线,

NSLog(@"Booking Documents viewDidLoad : %@",self.docsArray.count);

这是造成错误。 %@而不是%d。我想知道为什么xcode没有显示错误的正确理由。

谢谢大家的帮助。 :)

0
在BookingDocumentsViewController.h

@property(nonatomic, retain)NSmutableArray *docsArray; 

你尽可以在你的BookingDocumentsViewController.m做:

@synthesize docsArray; 

- (void)viewDidLoad 
{ 
    NSmutableArray *array = [NSmutableArray alloc]initWithArray:docsArray]; 
    [super viewDidLoad]; 
} 

然后当你推图

BookingDocumentsViewController *bdVc = [self.storyboard instantiateViewControllerWithIdentifier:@"BookingDocs"]; 
bdVc.orId = rl_id; 
bdVc.docsArray = self.documentsArray; 
[self.navigationController pushViewController:bdVc animated:YES]; 
[bdVc Release]; 
+1

在viewDidLoad中创建一个不在任何地方使用的本地数组有什么意义?这个地方没有太多的答案 – Abizern

+0

以及你可以定义该数组。h如果你想在其他区块使用它,我只是将重点放在传递数组价值的基础上......无论如何将在未来照顾。 – spider1983

2

也许考虑使用Segue。它为你实例化目标视图控制器。然后在您的源视图控制器实现

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

到达目的地的ViewController参考,并设置其数据。

BookingDocumentsViewController *bdVc = [segue destinationViewController]; 
bdVc.docsArray = self.documentsArray; 
相关问题