我与视图交互时应用程序崩溃了?

时间:2013-12-11 18:02:46

标签: ios objective-c core-data uiviewcontroller uitextfield

这是我的应用中的视图代码。出于某种原因,当我在这个视图中做任何事情时,应用程序崩溃并给我警告“线程1:信号SIGABRT”,我知道这意味着有一个例外,但我找不到它是什么。请有人帮忙吗?

//
//  NameSaveAsViewController.h
//  ShiftCalculator
//
//  Created by John on 21/11/2013.
//  Copyright (c) 2013 John. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "Foundation/Foundation.h"

@interface NameSaveAsViewController : UIViewController <UITextFieldDelegate> {

NSString *string5;
NSMutableArray *mArray;
NSUserDefaults *defaults;
IBOutlet UITextField *saveAsText;
}


@property (nonatomic, copy) IBOutlet UITextField *saveAsText;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator   
*persistantStoreCoordinator;


- (IBAction)saveAs:(id)sender;
- (IBAction)textFieldDidBeginEditing:(UITextField *)textField;
- (IBAction)textFieldDidEndEditing:(UITextField *)textField;
- (IBAction)dismissKeyboard:(id)sender;



@end

// 
//  NameSaveAsViewController.m
//  ShiftCalculator
//
//  Created by John on 21/11/2013.
//  Copyright (c) 2013 John. All rights reserved.
//

#import "NameSaveAsViewController.h" 
#import "AppDelegate.h"
#import "Shift.h"

@interface NameSaveAsViewController ()

@end


@implementation NameSaveAsViewController
@synthesize saveAsText;
@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistantStoreCoordinator = _persistantStoreCoordinator;



-(void)viewDidLoad {

[super viewDidLoad];

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
_managedObjectContext = [appDelegate managedObjectContext];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self  
action:@selector(dismissKeyboard:)];
[self.view addGestureRecognizer:tap];

}

- (void)dismissKeyboard:(id)sender
{
if ([saveAsText isEditing]) {
    [saveAsText resignFirstResponder];
}
}

- (void)textFieldDidBeginEditing:(UITextField *)textField {
saveAsText.placeholder = @"Shift Name";

} 

- (void)textFieldDidEndEditing:(UITextField *)textField {

}

- (void)saveAs:(id)sender
{
Shift *shift = [NSEntityDescription insertNewObjectForEntityForName:@"Shift" 
inManagedObjectContext:_managedObjectContext];
[shift setMake:saveAsText.text];

 }

@end

//
//  main.m
//  ShiftCalculator
//
//  Created by John on 21/11/2013.
//  Copyright (c) 2013 John. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

1 个答案:

答案 0 :(得分:0)

我认为您的问题可能是:

@property (nonatomic, copy) IBOutlet UITextField *saveAsText;

应该是

@property (nonatomic, weak) IBOutlet UITextField *saveAsText;