iphone - 用空字符串替换数组对象时出错

标签 iphone ios

NSMutableArray 中的两个在索引 0 处具有相同值时出现不可预测的错误,然后我想删除该对象并用空字符串替换对象。但是应用程序崩溃说

 -[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0xe2a06b0
  2012-03-22 14:36:48.181 golf eScorer[3849:11f03] *** Terminating app due to uncaught exception  
  'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: 
   unrecognized selector sent to instance 0xe2a06b0'  

当我使用断点调试而不是日志显示时

2012-03-22 14:36:44.548 golf eScorer[3849:11f03] ArrayOfGameidOfPlayerToRemove....(
2
)
2012-03-22 14:36:44.549 golf eScorer[3849:11f03] discardedId...(
2
)

这是我的代码行:

 if([[ArrayOfGameidOfPlayerToRemove objectAtIndex:0] isEqualToString:[discardedId 
    objectAtIndex:0]])
        {
            [ArrayOfGameidOfPlayerToRemove replaceObjectAtIndex:0 withObject:emptyString];
        }

更新:

我是这样解决的

   NSMutableArray *ArrayOfGameidOfPlayerToRemove = [yournsarray mutableCopy];

最佳答案

似乎变量 ArrayOfGameidOfPlayerToRemoveNSArray 的实例。您只能在 NSMutableArray

中替换对象

关于iphone - 用空字符串替换数组对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9819220/

相关文章:

iphone - 鉴于此代码,为什么后退按钮不会出现(UINavigationController 问题)

ios - TableView 单元格重用导致按钮标题在滚动时发生变化

ios - 如何实现嵌入 slider 来显示数据?

iphone - 旋转 UIView - willRotateToInterfaceOrientation 未被调用

iphone - 我是否需要在需要时手动将每个 *.m 文件添加到我的单元测试目标?

ios - 如何用 Storyboard 实现 RTPagingViewController?

iphone - 崩溃呈现模态视图 Controller

iphone - 如何从 ManagedObjectContext 中删除给定实体的所有对象

ios - 尝试在 iOS 中动态调整 UITableView 的大小时出现运行时异常

ios - 我如何将我的 ios 应用程序链接并同步到 cloudantnosqlite?