【问题标题】:EXC_BAD_ACCESS exception in the following code以下代码中的 EXC_BAD_ACCESS 异常
【发布时间】:2014-09-12 00:32:36
【问题描述】:
    NSMutableArray *quesArrayForPar0 = [[NSMutableArray alloc] initWithObjects:

[[NSMutableArray alloc] initWithObjects:@"We have a clearly stated vision for the next 5 years.", "-1", nil], 

[[NSMutableArray alloc] initWithObjects:@"Our organization has clearly established strategy to achieve the vision.", "-1", nil],

 [[NSMutableArray alloc] initWithObjects:@"This strategy is implemented uniformly and effectively throughout our organization.", "-1", nil], 

[[NSMutableArray alloc] initWithObjects:@"We are progressing as per our plan to realize this vision within the envisage time horizon.", "-1", nil]

, nil];

我真的不明白为什么上面的代码会抛出异常..!

【问题讨论】:

  • , "-1", 真的在你的代码中吗?
  • 哦..忘了把@放在“-1”之前..一个非常愚蠢的错误..
  • 也请仔细阅读this Raywenderlich 的文章。
  • @Shradha 如果我的回答对您有帮助,请接受。

标签: ios memory-management nsmutablearray automatic-ref-counting


【解决方案1】:

因为在内部可变数组中,您分配了两个不同的对象。一种是 Obj-C 字符串 @"" 和其他 C 字符串 ""

所以我更改了您的代码及其工作方式。

NSMutableArray *quesArrayForPar0 = [[NSMutableArray alloc] initWithObjects:
                                    [[NSMutableArray alloc] initWithObjects:@"We have a clearly stated vision for the next 5 years.", @"-1", nil],
                                    [[NSMutableArray alloc] initWithObjects:@"Our organization has clearly established strategy to achieve the vision.", @"-1", nil],
                                    [[NSMutableArray alloc] initWithObjects:@"This strategy is implemented uniformly and effectively throughout our organization.", @"-1", nil],
                                    [[NSMutableArray alloc] initWithObjects:@"We are progressing as per our plan to realize this vision within the envisage time horizon.", @"-1", nil]
                                    , nil];

【讨论】:

  • 一个是Obj-C字符串,另一个是C字符串
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-05
  • 1970-01-01
相关资源
最近更新 更多