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

我有上面的代码片段。我正在尝试加载一个新的视图控制器并将其可变数组(docsArray)对象分配给当前视图的可变数组(documentsArray <=this is not nil)

每当我执行上述代码时,我都会收到 EXC_BAD_ACCESS 错误。

但如果我评论第三行。它可以工作,但我无法让我的数组进入新视图。我什至试过[[NSMutableArray alloc] initWithArray:self.documentsArray];这个也不起作用。

但是,如果我使用bdVc.docsArray =[[[NSMutableArray alloc] init];它可以工作,但我又无法将我的可变数组放到新视图中。

编辑:但是第二行有 NSString 值。他们可以毫无问题地通过。

我在这里做错了什么?

我在控制台中没有收到任何错误,而是得到了这个。

在此处输入图像描述

4

3 回答 3

2

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

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

获取对目标视图控制器的引用并设置其数据。

BookingDocumentsViewController *bdVc = [segue destinationViewController];
bdVc.docsArray = self.documentsArray;
于 2012-11-12T12:15:51.790 回答
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];
于 2012-11-12T12:02:54.090 回答
0

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

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

这是导致错误的原因。%@ 而不是 %d。我想知道为什么 xcode 没有显示错误的正确原因。

谢谢大家的帮助。:)

于 2012-11-12T12:27:35.803 回答