在我的应用程序中,我有很多工厂使用这种类型的代码,除非我希望用户为他们查看的每个工厂保存他们自己的注释,否则效果很好......
在我的PerennialDataPurple.h
中// PerennialDataPurple.h
// Created by John Lein Feb. 2017.
// Copyright (c) 2017 Lein Design Inc. All rights reserved.
@interface PerennialDataPurple : NSObject
@property (nonatomic, strong) NSString* name;
@property (nonatomic, strong) NSString* namethumb;
...
@property (nonatomic, strong) NSString* image3Title;
*@property (nonatomic, strong) NSString* save_userNote;*
+(NSArray* )createMultipleSampleDishes;
@end
在我的PerennialDataPurle.m中,我有以下代码,除了再次保存笔记外...
// PerennialDataPurple.m
// Created by John Lein Feb. 2017.
// Copyright (c) 2017 Lein Design Inc. All rights reserved.
#import "PerennialDataPurple.h"
@implementation PerennialDataPurple
+(NSArray* )createSampleDishes{
PerennialDataPurple* purpleconeflower = [[PerennialDataPurple alloc] init];
purpleconeflower.name = @"Purple Cone Flower";
purpleconeflower.namethumb = @"Purple\rCone Flower";
...
purpleconeflower.image3Description = @"Put some information in here to describe the design feature of image 3";
purpleconeflower.save_userNote = [[NSUserDefaults standardUserDefaults] stringForKey:@"userNotes"];
我的详细控制器(PicDetailController.h)(除了save_userNote之外的工作)
//
// PicDetailController.h
//
// Created by John Lein Feb. 2017.
// Copyright (c) 2017 Lein Design Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "PerennialDataYellow.h"
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import "SMPageControl.h"
@interface PicDetailController : UIViewController <NSFetchedResultsControllerDelegate, UIActionSheetDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate, UIScrollViewDelegate>
{
// NSString *save_userNote;
BOOL pageControlBeingUsed;
UIImage *blurrredImage;
BOOL didEdit;
IBOutlet UITextView *userNotes;
}
// allows me to use the plant label over again...
@property (nonatomic, strong) IBOutlet UILabel *plantnameLabel;
@property (nonatomic, strong) IBOutlet UILabel *plantnameLabel2;
...
@property (nonatomic, retain) IBOutlet UITextView *userNotes;
- (IBAction)handleSingleTap:(id)sender;
- (IBAction)emailButton:(id)sender;
- (IBAction)saveAction:(id)sender;
- (IBAction)clearNote:(id)sender;
@end
我的详细控制器(PicDetailController.m)可以正常工作,它确实保存了save_userNotes,但它为我查看的每个工厂保存了相同的注释。因此,虽然它成功保存了用户输入的注释,但它并不是每个记录(工厂)都是唯一的...我不会在PerennialDataPurple.h文件中回调这个东西来建立连接......
// PicDetailController.m
// Created by John Lein Feb. 2017.
// Copyright (c) 2017 Lein Design Inc.. All rights reserved.
- (void)saveAction:(id)sender
{
NSString *valueToSave = userNotes.text;
[[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"userNotes"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSString *text = [[NSUserDefaults standardUserDefaults]objectForKey:@"userNotes"];
self.userNotes.text = text;
}
注意在第一张图片中 - 用户输入的注释已保存...如果我杀了应用程序,强制退出,并返回它保存...但是没有保存到每个工厂的独特......所以当我查看第二张或第三张或第四张图像时,相同的用户注释出现......
任何想法如何使这项工作如此EACH用户注释是每个工厂独有的......
我感谢任何帮助或见解...