I am writing an app that notifies user when its time to take his/her medicine. The label at the top of the page shows a date and the tableView
gets populated with medicine names and times that need to be taken on that particular day. Now the sections get populated on the basis of number of medicines to be taken on that day. So the number of sections are dynamically changing over time; a medicine is scheduled to be taken on that particular day. Whenever the user takes a medicine, it is stored in DB as a variable that changes to "1"
else it remains "0"
.
Also I know that I need to reload section of that particular medicine on that day.
Now the question is how do I achieve that? How to reload a particular section?
for(NSManagedObject *mo in secondEntityArray) {
NSDate *temp1 = [mo valueForKey:@"date"];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString * temp2 = [dateFormatter stringFromDate:temp1];
NSDate *temp3 = [dateFormatter dateFromString:temp2];
NSDate * temp4 = [dateFormatter dateFromString:_dateLabel.text];
if([temp3 compare:temp4] == NSOrderedSame) {
if([[mo valueForKey:@"isNotificationFired"] isEqualToString:@"1"] && [[mo valueForKey:@"repeatDays"] isEqualToString:@"Everyday"]) {
//Reflect changes in tableView section
}
}
}
If you want to reload your table view while also saving and restoring any selections, you should take a copy of the indexPathsForSelectedRows property before the reload, then re-apply those selections after calling reloadData() . With that in place, you can now call yourTableView.
reloadData()Reloads the rows and sections of the table view.
Swift 3
NSIndexSet is nothing special
tableView.reloadSections([1, 2, 3], with: .none)
It's just an array. Crazy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With