我正在做一个应用程序作为初学者以获得一些经验,我正在制作一个简单的应用程序,将分配存储在表格视图中。所以我有一个表视图作为主视图和一个加号按钮,该按钮拉出一个模式视图控制器,允许用户输入有关 - 类名称、作业标题、作业描述、截止日期和开关的信息/关闭通知。这些值存储在 AssignmentInfo 模型中。我需要能够存档(NSCoding)这些值,并在输入新数据时添加到它们。以下是一些示例代码,可能有助于提供更好的想法:
分配信息.h -
@property (nonatomic,strong)NSString *className;
@property (nonatomic,strong)NSString *assignmentDescription;
@property (nonatomic,strong)NSString *assignmentTitle;
@property (nonatomic,strong)NSString *dateTimeString;
@property (nonatomic)bool notifcationStatus;
AddEditViewController.m -
{
IBOutlet UIDatePicker *dateTimePicker;
}
@property (nonatomic, strong) IBOutlet UITextField *className;
@property (nonatomic, strong) IBOutlet UITextField *assignmentTitle;
@property (nonatomic, strong) IBOutlet UITextField *assignmentDescription;
@property (nonatomic, strong) IBOutlet UISwitch *procrastinationNotificationSwitch;
@property (nonatomic,strong)AssignmentInfo *assignmentInfo;
AddEditViewController.m -
- (IBAction)addTheInfo:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;
NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date];
self.assignmentInfo.className = self.className.text;
self.assignmentInfo.assignmentTitle = self.assignmentTitle.text;
self.assignmentInfo.assignmentDescription = self.assignmentDescription.text;
self.assignmentInfo.dateTimeString = dateTimeString;
NSLog(@"%@",self.assignmentInfo.className);
[self dismissViewControllerAnimated:YES completion:nil];
}