2013-10-14 2 views
-2

У меня есть это:NSMutableArray от NSDictionary

NSMutableArray *tableData; 
NSMutableArray *thumbnails; 
NSMutableArray *prepTime; 


NSString *path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"]; 
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; 
tableData = (NSMutableArray *)[dict objectForKey:@"RecipeName"]; 
thumbnails = (NSMutableArray *)[dict objectForKey:@"Thumbnail"]; 
prepTime = (NSMutableArray *)[dict objectForKey:@"PrepTime"]; 

И я хочу сделать это:

- (void)tableView:(UITableView *)tableView commitEditingStyle:  
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableData removeObjectAtIndex:indexPath.row]; 
    [thumbnails removeObjectAtIndex:indexPath.row]; 
    [tableData removeObjectAtIndex:indexPath.row]; 
    [tableView reloadData]; 
} 

Но он терпит неудачу с:

2013-10-14 16: 58: 22,202 SimpleTable [8421: 11303] * Завершение приложения из-за неперехваченного исключения «NSInternalInconsistencyException», причина: '- [__ NSCFArray removeObjectAtIndex:]: метод мутирования, отправленный в неизменяемый объект' * Первый стек бросить вызов: (0x1c93012 0x10d0e7e 0x1c92deb 0x1d13c4f 0x29bd 0xd0d34 0x20e97b 0x10e4705 0x182c0 0x18258 0xd9021 0xd957f 0xd9056 0x2a9f4d 0x10e4705 0x182c0 0x18258 0xd9021 0xd957f 0xd86e8 0x47cef 0x47f02 0x25d4a 0x17698 0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 0x14ffc 0x1ced 0x1c15) LibC++ ABI .dylib: terminate called throwing exception

Как правильно сделать словарь в mutableArray?

+0

попробовать это tableData = (NSMutableArray *) [[ДИКТ objectForKey: @ "RecipeName"] mutableCopy] –

+0

Что каждый из 'objectForKey's вернуться? – Popeye

ответ

4

[[dict objectForKey: @ "RecipeName"] mutableCopy] должен делать трюк!

Edit: Вы, возможно, придется бросить его, как так [(NSArray *) [Dict objectForKey: @ "RecipeName"] mutableCopy]

+0

Вы правы, просто нужно подождать 6 минут, чтобы применить правильный ответ. спасибо – Cheese

2

В своем коде вы удаляете объект дважды из tableData

[tableData removeObjectAtIndex:indexPath.row]; 

я должен Следом

- (void)tableView:(UITableView *)tableView commitEditingStyle: 
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableData removeObjectAtIndex:indexPath.row]; 
    [thumbnails removeObjectAtIndex:indexPath.row]; 
    [prepTime removeObjectAtIndex:indexPath.row]; 
    [tableView reloadData]; 
} 
+1

Хотя это верно, ошибка говорит «метод мутации, отправленный в неизменяемый объект», что означает, что у него есть NSarray и вызывает методы, принадлежащие NSMutableArray –

+0

, спасибо, просто опечатал мой третий массив – Cheese

2

Благодаря Kris Gellci, это действительно сделал трюк:

tableData = [[dict objectForKey:@"RecipeName"] mutableCopy]; 
thumbnails = [[dict objectForKey:@"Thumbnail"] mutableCopy]; 
prepTime = [[dict objectForKey:@"PrepTime"] mutableCopy]; 
Смежные вопросы