Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在这种情况下可能会返回零。。。这可能是您在应用程序代理中设置内容的方式有问题。。。 #import "CCCFlipsideViewController.h" #import "CCCAppDelegate.h" #import "CCCMainViewC_Ios_Objective C_Core Data_Save - Fatal编程技术网

Ios 在这种情况下可能会返回零。。。这可能是您在应用程序代理中设置内容的方式有问题。。。 #import "CCCFlipsideViewController.h" #import "CCCAppDelegate.h" #import "CCCMainViewC

Ios 在这种情况下可能会返回零。。。这可能是您在应用程序代理中设置内容的方式有问题。。。 #import "CCCFlipsideViewController.h" #import "CCCAppDelegate.h" #import "CCCMainViewC,ios,objective-c,core-data,save,Ios,Objective C,Core Data,Save,在这种情况下可能会返回零。。。这可能是您在应用程序代理中设置内容的方式有问题。。。 #import "CCCFlipsideViewController.h" #import "CCCAppDelegate.h" #import "CCCMainViewController.h" #import "MessageDetails.h" @interface CCCFlipsideViewController () { // NSManagedObjectContext *context;

在这种情况下可能会返回零。。。这可能是您在应用程序代理中设置内容的方式有问题。。。
#import "CCCFlipsideViewController.h"
#import "CCCAppDelegate.h"
#import "CCCMainViewController.h"
#import "MessageDetails.h"

@interface CCCFlipsideViewController ()
{
   // NSManagedObjectContext *context;
}
@end

@implementation CCCFlipsideViewController
@synthesize allMessageDetails;
@synthesize managedObjectContext;

- (void)awakeFromNib
{
    [super awakeFromNib];

    CCCAppDelegate *appDelegateController = [[CCCAppDelegate alloc]init];
    self.managedObjectContext = appDelegateController.managedObjectContext;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription
                                   entityForName:@"MessageDetails" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

    NSError *error;

    self.allMessageDetails = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];

    /*
    NSManagedObject *managedObject; = [_fetchedResultsController valueForKey:@"to"];
    self.toTextField.text = managedObject to;

    messageDetails.to = [allMessageDetails firstObject];
    self.toTextField.text = messageDetails.to;

    messageDetails.message = [allMessageDetails valueForKey:@"message"];
    self.messageTextField.text = messageDetails.message;
    */
    NSLog(@"The 'to' is currently at %@ after viewdidload", self.toTextField.text);

    }

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
   return [textField resignFirstResponder]; //function says that if (bool) the text field is open and the keyboard hits return, text field is to resign first responder.
}

#pragma mark - Actions
- (IBAction)done:(id)sender
{
    [self.delegate flipsideViewControllerDidFinish:self];
}

- (IBAction)resignFirstResponder:(id)sender {

    [self.toTextField resignFirstResponder];
    [self.messageTextField resignFirstResponder];
    NSLog(@"Resigned First Responder");
}


- (IBAction)save:(id)sender {

    // Create a new instance of the entity managed by the fetched results controller.
   NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
    NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
    NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];

    // If appropriate, configure the new managed object.
    [newManagedObject setValue:self.toTextField.text forKey:@"to"];
    [newManagedObject setValue:self.messageTextField.text forKey:@"message"];

    // Save the context.
    NSError *error = nil;
    if (![context save:&error]) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }


}


#pragma mark -
#pragma mark Fetched results controller

- (NSFetchedResultsController *)fetchedResultsController {

    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }

    /*
     Set up the fetched results controller.
     */
    // Create the fetch request for the entity.
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"MessageDetails" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:20];

    // Edit the sort key as appropriate.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"to" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;


    NSError *error = nil;
    if (![_fetchedResultsController performFetch:&error]) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return _fetchedResultsController;
}


@end
[((NSObject*)[UIApplication sharedApplication].delegate) valueForKey: @"managedObjectContext"];
- (IBAction)save:(id)sender {

    NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"MessageDetails" inManagedObjectContext:self.managedObjectContext];

    // If appropriate, configure the new managed object.
    [entity setValue:self.toTextField.text forKey:@"to"];
    [entity setValue:self.messageTextField.text forKey:@"message"];

    // Save the context.
    NSError *error = nil;
    [self.managedObjectContext save:&error]

    if (error) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
     */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
AppDelegate* appDelegateController;
appDelegateController = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- (NSManagedObjectContext*)managedObjectContext {
    return appDelegateController.managedObjectContext;
}
self.managedObjectContext = [self managedObjectContext];