简体   繁体   中英

Adding Record using Core Data with Tab Bar Controller

I am trying to add a record to the database using core data. The appDelegate has the managed object model, context, and store coordinator setup in it. When the app is launched and I query the fetchResultsController method in one of my views the database is created matching the scheme with the correct table names and columns in it. However the problem comes when I try to add a record to the table.

The BurpListNavController.h file has the following contents (I am just learning):

#import <UIKit/UIKit.h>
@class BurpRecordController;

@interface BurpListNavController : UINavigationController <NSFetchedResultsControllerDelegate> {

 BurpRecordController *burpRecordController;
 NSFetchedResultsController *fetchedResultsController;
 NSManagedObjectContext *managedObjectContext;

}

@property (nonatomic, retain) IBOutlet BurpRecordController *burpRecordController;
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;

- (void)saveBurpLocal:(id)sender;
@end

I then have a view that records the burp, yes another one of the thousands of burp applications. haha. The following code is as follows:

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>

@class BurpLocal;  
@class BurpListNavController;

@interface BurpRecordController : UIViewController <AVAudioRecorderDelegate, UIActionSheetDelegate> {

 /*** Outlets to talk to the view ***/
 IBOutlet UITextField *burpName;
 IBOutlet UIButton *_recordButton;

 /*** Standard Variables ***/
 NSURL *recordedTmpFile;
 //AVAudioRecorder *recorder;
 NSError *error; 

 BurpLocal *burpLocal;
 BurpListNavController *burpListNavController;
}

/*** Properties ***/
@property (nonatomic, retain) IBOutlet  UITextField *burpName;
@property (nonatomic, retain) IBOutlet  UIButton *recordButton;
@property (nonatomic, assign) IBOutlet BurpListNavController *burpListNavController;
@property(nonatomic, retain) BurpLocal *burpLocal;

/*** Method ***/
-(IBAction)saveRecording:(id)sender;

-(void)applicationWillTerminate:(NSNotification *)notification;

@end

When the end-user pushes the "save" button it calls the "saveRecording" method which I can step into and is great. Then I try to call the following line of code within the "saveRecording" method: [burpListNavController saveBurpLocal:sender]; thinking this will call the "saveBurpLocal" method in the nav controller and it just steps over it, does not stop at the break point in the nav controller method and then just goes to the end of the current "saveRecording" function. Does not write a record to the database or anything.

Please help! This is driving me crazy.

It's difficult to tell without more code; but it sounds like burpListNavController has not been set. When you step through the saveRecording: method, is the value of burpListNavController 0x0? If it is then you have forgotten to set that iVar somewhere.

If you have come from another language this might sound a little strange, as usually calling a method on a null pointer you cause you to crash. This isn't the case in Objective-C though, it is perfectly legal to send a message to nil; but don't expect anything to actually happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM