问题描述
- 表单元在标视图中的位置显示错误
-
DataModel.h#import "DataModel.h" #import <CoreData/CoreData.h> #import "SettingsEntity.h" #import "Constants.h" @implementation DataModel NSManagedObjectContext *managedObjectContextEntity; NSManagedObjectContext *managedObjectContextMessage; NSManagedObjectModel *managedObjectModel; NSPersistentStoreCoordinator *persistentStoreCoordinator; NSEntityDescription *theSettingsEntity; NSEntityDescription *theMessagesEntity; -(id) init { NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"SOW" withExtension:@"momd"]; managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; NSError *error = nil; NSURL *storeURL = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:[Constants SQLLiteDB]]; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } if (persistentStoreCoordinator != nil) { managedObjectContextEntity = [[NSManagedObjectContext alloc] init]; [managedObjectContextEntity setPersistentStoreCoordinator:persistentStoreCoordinator]; managedObjectContextMessage = [[NSManagedObjectContext alloc] init]; [managedObjectContextMessage setPersistentStoreCoordinator:persistentStoreCoordinator]; } theSettingsEntity = [NSEntityDescription entityForName:@"SettingsEntity" inManagedObjectContext:managedObjectContextEntity]; theMessagesEntity = [NSEntityDescription entityForName:@"MessageEntity" inManagedObjectContext:managedObjectContextMessage]; return self; } -(void) SaveSetting: (SettingsEntity *)setting { NSError *error = nil; if (managedObjectContextEntity != nil) { if ([managedObjectContextEntity hasChanges] && ![managedObjectContextEntity save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirmation" message:@"Settings were saved successfully." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil]; [alert show]; } } } -(void) SaveMessage: (MessageEntity *)message { NSError *error = nil; if (managedObjectContextMessage != nil) { if ([managedObjectContextMessage hasChanges] && ![managedObjectContextMessage save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } } -(NSArray *) GetSettingsResult { NSManagedObjectContext *context = managedObjectContextEntity; NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:theSettingsEntity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"enteredDateTime" ascending:NO]; NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; NSArray *results = [context executeFetchRequest:request error:nil]; return results; } -(SettingsEntity *) GetSettingsEntity { SettingsEntity *settingsEntity = [NSEntityDescription insertNewObjectForEntityForName:[theSettingsEntity name] inManagedObjectContext:managedObjectContextEntity]; return settingsEntity; } -(NSArray *) GetMessageResult { NSFetchRequest *request = [self GetMessageFetchRequest]; NSArray *results = [managedObjectContextMessage executeFetchRequest:request error:nil]; return results; } -(NSFetchRequest *) GetMessageFetchRequest { NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:theMessagesEntity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sentDateTime" ascending:NO]; NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; return request; } -(NSFetchedResultsController *) GetMessageFetchResultsController { NSFetchRequest *fetchRequest = [self GetMessageFetchRequest]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContextMessage sectionNameKeyPath:@"typeMessage" cacheName:nil]; return aFetchedResultsController; } -(MessageEntity *) GetMessageEntity { MessageEntity *mEntity = [NSEntityDescription insertNewObjectForEntityForName:[theMessagesEntity name] inManagedObjectContext:managedObjectContextMessage]; return mEntity; } @end
显示出来的 history table view结果是:
可以看见email和call的显示位置对应错误,不知道为什么?请大家帮忙解答。
解决方案
数据错位,只能是通过section 和row 取数据时,楼主没有找到对应的数据。建议楼主 将逻辑先在纸上弄清楚 然后再通过代码去显示
时间: 2024-10-26 05:43:24