-2

Recently I use NSTextTable draw table. I want change some attribute of selected block,so save selected paragraphs into dictionary. After I copy the block of paragraph, once I call method [NSTextTableBlock setBorderColor:], raise an error:

-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x6000002442c0

I try many times, finally found a phenomenon, which is if I don't copy block, setBorderColor: is OK. Anyone know relation of [NSTextTableBlock copy] and this error, why [NSTextTableBlock setBorderColor:] cause this error? I'm quite confuse about this error. Thanks in advance.

John Chen
  • 27
  • 6
  • I know NSArray and NSMutableArray, but the question is I didn't use any NSArray to save my instance value, I just copy a NSTextTableBlock from dictionary! – John Chen Nov 12 '14 at 03:16

1 Answers1

4

NSArray does not have the selector replaceObjectAtIndex:withObject: (so you can't call it). You are actually trying to modify an NSArray which can not be modified like that. You probably want NSMutableArray instead. You can create an NSMutableArray from an NSArray, call your method and then replace your reference to the original array like this:

NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:array];
[mutableArray replaceObjectAtIndex:index withObject:object];
array = mutableArray;//now the array has been "updated"
lindon fox
  • 3,298
  • 3
  • 33
  • 59
  • The question is I didn't use any NSArray to save my instance value, I just copy a NSTextTableBlock from dictionary. Thank you all the same. – John Chen Nov 12 '14 at 03:04