I keep on getting the error
When I am adding a cell to a tableview that a user can name. I am doing this by having an add button on the table view then once pressed goes to a new view controller with a text field that a user can input a name.
Here is how I am saving to the NSUserDefault
I am calling on the data here
This is how I am assigning the value to the cells in my cellForRowAtIndexPath
On my other view controller that is doing the adding I am sending the data with the following code
Any suggestions on what I have to do to fix my error?
Code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
When I am adding a cell to a tableview that a user can name. I am doing this by having an add button on the table view then once pressed goes to a new view controller with a text field that a user can input a name.
Here is how I am saving to the NSUserDefault
Code:
-(void)addNewSectionWithName:(NSString *)name {
[tableInfo addObject:name];
[self.tableView reloadData];
NSString *valueToSave = name;
[[NSUserDefaults standardUserDefaults]
setObject:valueToSave forKey:@"customCellName"];
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
}
I am calling on the data here
Code:
- (void)reloadCells {
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"customCellName"];
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
[tempArray addObject:savedValue];
[tableInfo addObjectsFromArray:tempArray];
}
This is how I am assigning the value to the cells in my cellForRowAtIndexPath
Code:
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"customCellName"];
cell.textLabel.text = savedValue;
On my other view controller that is doing the adding I am sending the data with the following code
Code:
-(void)addNewSection
{
if (sectionName.text.length >0)
{
[sectionName resignFirstResponder];
[self dismissModalViewControllerAnimated:YES];
[firstViewController addNewSectionWithName:sectionName.text];
[firstViewController.tableView reloadData];
}
}
Any suggestions on what I have to do to fix my error?