我的设置页面仍然存在问题,我似乎无法访问核心数据。出于某种原因,内容甚至没有改变。我不知道自己做错了什么
我的核心数据设置如下:
我的“设置”页面如下所示:
现在,我正在尝试的是在视图加载时停用Override-Slider和Time-Format选择器。我在viewDidLoad中这样做,它的工作原理。按下“编辑”按钮后,.userInteractionEnabled将设置为“是”,并发生一些其他可视更改(标题和编辑 - 保存按钮文本更改)。
我试图使用我的设置实体的settingsSysTimeFormatOverride属性来记住"覆盖系统时间格式的位置"滑块。 但我无法将其存储在持久性存储器中: - (
这是文件: 我的SettingsViewController.m:
#import "SettingsViewController.h"
@interface SettingsViewController ()
@end
@implementation SettingsViewController
int test1=0;
@synthesize editSetting;
- (void)viewDidLoad
{
[super viewDidLoad];
// prepare Interface
[self setTitle:@"Edit"];
_editSaveButton.title = @"Edit";
_timeOverrideSlider.userInteractionEnabled = NO;
}
- (IBAction)cancel:(UIBarButtonItem *)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)editSave:(UIBarButtonItem *)sender
{
if ([_editSaveButton.title isEqualToString:@"Edit"])
{
// enable UI-Elements
_timeOverrideSlider.userInteractionEnabled = YES;
[self setTitle:@"Edit Settings"];
_editSaveButton.title = @"Save";
} else if ([_editSaveButton.title isEqualToString:@"Save"])
{
// disable UI-Elements
_timeOverrideSlider.userInteractionEnabled = NO;
[self setTitle:@"Edit"];
_editSaveButton.title = @"Edit";
[super saveAndDismiss];
}
}
- (IBAction)timeOverride:(UISwitch *)sender
{
// Nothing yet, comes when saving the position works
}
@end
我的设置ViewController.h:
#import <UIKit/UIKit.h>
#import "Setting.h"
#import "CoreViewController.h"
@interface SettingsViewController : CoreViewController
@property (nonatomic, strong)Setting *editSetting;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *editSaveButton;
@property (strong, nonatomic) IBOutlet UISwitch *timeOverrideSlider;
- (IBAction)cancel:(UIBarButtonItem *)sender;
- (IBAction)editSave:(UIBarButtonItem *)sender;
- (IBAction)timeOverride:(UISwitch *)sender; // do I really need this IBAction?
@end
我的(模态)Segue&#34; toSettings&#34;从主页:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell*)sender
{
if ([[segue identifier]isEqualToString:@"toSettings"])
{
UINavigationController *settingsViewController = segue.destinationViewController;
SettingsViewController *editSettingsViewController = (SettingsViewController*)settingsViewController.topViewController;
NSIndexPath *indexPath = [self.fetchedResultsController objectAtIndexPath:0];
Setting *editSettings = (Setting*)[self.fetchedResultsController objectAtIndexPath:indexPath];
editSettingsViewController.editSetting = editSettings;
}
}
我的segue使用&#34; UITableViewCell&#34;作为发件人,因为我在项目中有其他观点。
在我的CoreViewController.m中我有saveAndDismiss方法:
-(void)saveAndDismiss
{
NSError *error = nil;
if ([self.managedObjectContext hasChanges]) {
NSLog(@"SAVE & DISMISS conetx has changed");
if (![self.managedObjectContext save:&error]) { // save failed
NSLog(@"Save failed: %@", [error localizedDescription]);
} else { // save succeeded
NSLog(@"Save Succeeded");
}
}
[self dismissViewControllerAnimated:YES completion:nil];
}
但是我从来没有从那里得到NSLog-Output,因为我的核心数据永远不会改变..
任何人都可以请指出,错误在哪里?
谢谢你们