我正在使用 NSMutableArray
并尝试从 NSMutableArray
中删除对象,然后它崩溃了
[[self.sectionsArray objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
.h
就像
NSMutableArray *sectionsArray;
@property (nonatomic, retain) NSMutableArray *sectionsArray;
.m is like:
@synthesize sectionsArray;
#pragma mark - TableView Delegate
- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath
{
// Perform segue to candy detail
NSLog(@"section: %d row: %d", indexPath.section, indexPath.row);
NSLog(@"section :%@", [[self.sectionsArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]);
[[self.sectionsArray objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];
// [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
崩溃日志是这样的:
2014-01-28 11:56:24.989 CandySearch[828:c07] section: 2 row: 0
2014-01-28 11:56:24.991 CandySearch[828:c07] section :<Candy: 0x75a5a70>
2014-01-28 11:56:24.992 CandySearch[828:c07] -[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x75d8c90
2014-01-28 11:56:24.992 CandySearch[828:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x75d8c90'
*** First throw call stack:
(0x1c9b012 0x10d8e7e 0x1d264bd 0x1c8abbc 0x1c8a94e 0x370d 0xcc285 0xcc4ed 0xad65b3 0x1c5a376 0x1c59e06 0x1c41a82 0x1c40f44 0x1c40e1b 0x1bf57e3 0x1bf5668 0x1cffc 0x1d52 0x1cc5 0x1)
libc++abi.dylib: terminate called throwing an exception
我可以看到该索引处的对象。但它仍然崩溃 为什么?
位于索引“indexPath.section”上的数组是一个 NSArray 对象,而不是一个 NSMutableArray 只需阅读崩溃日志: NSArrayI removeObjectAtIndex:
请检查你的sectionArray的对象
关于ios - iOS 中 NSmutableArrays 的 NSMuatableArray 的 RemoveObjectAtIndex 正在崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21398549/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |