@property (strong, nonatomic)NSMutableArray *billsArray;
- (void)viewDidLoad {
[super viewDidLoad];
self.billsUserDefault = [NSUserDefaults standardUserDefaults];
self.billsArray = [[NSMutableArray alloc] init];
self.billsArray = [self getBillsArray];
}
- (NSMutableArray *)getBillsArray {
NSMutableArray *billsArr = [self.billsUserDefault objectForKey:@"billArray"];
return billsArr;
}
- (void)AddOneBill:(Bill *)bill {
// add bill to array
[self.billsArray addObject:bill];
// store the new bill
[self.billsUserDefault setObject:self.billsArray forKey:@"billArray"];
[self.billsUserDefault synchronize];
// reload the table view
[self.billTableView reloadData];
}
The addObject
method in addOneBill:
method does not work.
I have googled the same problem, others also met this problem. The answers suggested to add [[NSMutableArray alloc] init]
for mutable array. I did but not works.