2 mapmapm MapMapM 于 2013.01.14 10:07 提问

表单元在标视图中的位置显示错误

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结果是:

CSDN移动问答

可以看见email和call的显示位置对应错误,不知道为什么?请大家帮忙解答。

1个回答

zj382561388
zj382561388   2015.08.24 23:33

数据错位,只能是通过section 和row 取数据时,楼主没有找到对应的数据。建议楼主 将逻辑先在纸上弄清楚 然后再通过代码去显示

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!