Soy principiante en iOS y XCode, y estoy trabajando a través de un Núcleo de Datos de tutorial y estoy realmente confundido. Continuamente me sale el error en los logs de errores de las siguientes:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
iPhone Simulator 235, iPhone OS 4.2 (iPad/8C134)
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x010a6be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00e9b5c2 objc_exception_throw + 47
2 CoreFoundation 0x0105f628 +[NSException raise:format:arguments:] + 136
3 Foundation 0x000b447b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x00336a0f -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8424
5 UIKit 0x00325f81 -[UITableView insertRowsAtIndexPaths:withRowAnimation:] + 56
6 SimpleRes 0x00002496 -[RootViewController addReservation] + 465
7 UIKit 0x002b9a6e -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x004c7167 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
9 UIKit 0x002b9a6e -[UIApplication sendAction:to:from:forEvent:] + 119
10 UIKit 0x003481b5 -[UIControl sendAction:to:forEvent:] + 67
11 UIKit 0x0034a647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
12 UIKit 0x003491f4 -[UIControl touchesEnded:withEvent:] + 458
13 UIKit 0x002de0d1 -[UIWindow _sendTouchesForEvent:] + 567
14 UIKit 0x002bf37a -[UIApplication sendEvent:] + 447
15 UIKit 0x002c4732 _UIApplicationHandleEvent + 7576
16 GraphicsServices 0x018bda36 PurpleEventCallback + 1550
17 CoreFoundation 0x01088064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
18 CoreFoundation 0x00fe86f7 __CFRunLoopDoSource1 + 215
19 CoreFoundation 0x00fe5983 __CFRunLoopRun + 979
20 CoreFoundation 0x00fe5240 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x00fe5161 CFRunLoopRunInMode + 97
22 GraphicsServices 0x018bc268 GSEventRunModal + 217
23 GraphicsServices 0x018bc32d GSEventRun + 115
24 UIKit 0x002c842e UIApplicationMain + 1160
25 SimpleRes 0x00001ab0 main + 102
26 SimpleRes 0x00001a41 start + 53
)
Aquí está mi addReservation código:
-(void)addReservation{
//Create and configure a new instance of the Event entity.
Reservations *reservation = (Reservations *)[NSEntityDescription insertNewObjectForEntityForName:@"Reservations" inManagedObjectContext:managedObjectContext];
[reservation setEnd_Time: [[NSDate alloc]init]];
[reservation setReservation_Date:[[NSDate alloc]init]];
[reservation setStart_Time:[NSDate date]];
[reservation setParty_Size: [NSNumber numberWithInt:4]];
[reservation setPhone_Number: [NSNumber numberWithInt: 1234567890]];
[reservation setName: @"Keith"];
[reservation setNotes: @"He's really hot!"];
[reservation setPerson_Responsible: @"Lisa"];
[reservation setTables_Excluded: @"3,5,8"];
NSError *error = nil;
if (![managedObjectContext save:&error]) {
}
[resArray insertObject:reservation atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
Creo que mi resArray no es la obtención de los datos desde el método que yo de entrada en forma programática, pero no estoy seguro, y no estoy seguro de cómo solucionarlo.
Cualquier ayuda es muy apreciada.
Si usted sigue el iOS de Apple Core de Datos de tutorial, los archivos que son generados por la plantilla de la línea return 0; para la numberOfSectionsInTable método de delegado. Acaba de cambiar la línea de retorno de 1 y que debe ser bien entonces.
OriginalEl autor Keith Boruta | 2011-02-18
Me gustaría echar un vistazo a la implementación de
El error especificado se produce cuando el valor devuelto desde numberOfRowsInSection no es igual al valor anterior más el número de filas que se agrega el uso de insertRowsAtIndexPaths. Si su aplicación de numberOfRowsInSection es el uso de [myArray count], a continuación, asegúrese de que la instancia de array se utiliza es la misma en la que se agrega la reserva de la entrada. Si usted no ha implementado este método, entonces ese sería su problema. Aquí es un ejemplo de cómo ese método debe buscar:
Como una copia de seguridad, usted puede agregar las declaraciones de registro de la lista el tamaño de la matriz antes y después de la adición, y en el interior de la numberOfRowsInSection función.
OriginalEl autor Kris Babic
El fin de que usted delete/insert desde el formato tableview y delete/insert desde el origen de datos subyacente puede ser importante. La documentación de Apple tiene la actualización de la vista por primera vez y, a continuación, el origen de datos. Sin embargo, eliminar o insertar desde el punto de vista llama internamente
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
que, si eres como yo, devuelve elcount
de el origen de datos subyacente. Porque esto no ha cambiado, el tiempo de ejecución se quejan y se estrellan. Por lo tanto, eliminar de su origen de datos en primer lugar, luego la vista.reloadData
al final es redundante. Usted debe utilizarbegin
/endUpdates
para la sincronización de la tabla a los datos subyacentes de OreloadData
para sólo volver a cargar todo (que es el más costoso de la CPU sabio y que probablemente no se ven tan bien para el usuario). Pero no hay necesidad de hacer ambas cosas. He presentado una edición.OriginalEl autor Peter Kelly
Me parece como si se va a insertar el objeto antes de accually hacer los cambios. Podría estar equivocado, como yo también soy un novato!
OriginalEl autor Charlie
(NSInteger)en formato tableview:(UITableView *)en formato tableview numberOfRowsInSection:(NSInteger)sección {
}
(void)formato tableview:(UITableView *)en formato tableview commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
si (editingStyle == UITableViewCellEditingStyleDelete) {
}
Esto funciona al eliminar y añadir registros a la tabla de datos con fetchedResultsController.
OriginalEl autor Graham