I have 2 Controllers, a AssignmentViewController and a UITableViewController. Whenever an assignment is created and the saved button is clicked, I need to send that Assignment object to my UITableViewController (Using delegation). The TableView then needs to archive it in a file in a NSMutableArray (TableView must do the archiving/unarchiving for this app).
And whenever the TableView is loaded, it needs to unarchive the array and have the Homework Objects displayed in the table cells.
I have the code started, but I don't really know what Im doing correctly and incorrectly.
The app is supposed to work in this order. Enter assignment info and press save -> send new assignment object to TableViewController using delegation -> Archive object in NSMutableArray to a file ->Whenever Table view is on the screen, unarchive array and display assignment objects in cells.
Here is what I have:
AssignmentViewController.h
@interface Assignment : UIViewController
<
UITextViewDelegate,
AssignmentTableControllerDelegate
//Error:Cannot find protocol declaration "AssignmentTableControllerDelegate"
>
@property(nonatomic) IBOutlet UITextField *ClassNameField;
@property(nonatomic) IBOutlet UILabel *ClassNameLabel;
@property(nonatomic) IBOutlet UITextField *AssignmentTitleField;
@property(nonatomic) IBOutlet UILabel *AssignmentTitleLabel;
@property (nonatomic, strong) Homework *homeworkAssignment;
- (IBAction)Save:(UIButton *)sender;
@end
AssignmentViewController.m
- (IBAction)Save:(UIButton *)sender {
self.homeworkAssignment = [[Homework alloc] init];
self.homeworkAssignment.className = self.ClassNameField.text;
self.homeworkAssignment.assignmentTitle = self.AssignmentTitleField.text;
//Sending info over to TableController
self.assignmentTableController.delegate= self;
self.assignmentTableController.homeworkInTable.className= self.ClassNameField.text;
self.assignmentTableController.homeworkInTable.assignmentTitle=self.AssignmentTitleField.text;
AssignmentTABLEController.h
#import "Assignment.h"
@protocol AssignmentTableControllerDelegate;
@interface AssignmentTableController : UITableViewController
@property (nonatomic, strong) Homework *homeworkInTable;
@property (nonatomic, assign) id <AssignmentTableControllerDelegate> delegate;
@property (nonatomic,strong) NSMutableArray *MyHomeworkArray;
-(IBAction)ArchiveData:(id)sender;
@end
@protocol AssignmentTableControllerDelegate <NSObject>
-(NSMutableArray *)UnarchiveData;
@end
AssignmentTABLECONTROLLER.M (All I did was add these 2 methods)
-(void)ArchiveData:(id)sender
{
[self.MyHomeworkArray addObject:self.homeworkInTable];
NSString *filePath = [self dataFilePath];//file created
//Archive my object
[NSKeyedArchiver archiveRootObject:self.MyHomeworkArray toFile:filePath];
}
-(NSMutableArray *)UnarchiveData
{
Homework *archivedHomework = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
//Error:use of undeclared identifier:filePath^^
}
I am new to this so I know theres a lot wrong. I "think" I am passing the info over correctly from AssignmentViewController with delegation. But I am pretty sure I am not archiving/unarchiving correctly at all. I am not sure how to separate the archiving/unarchiving code and then display in the table.