Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload sections in UITableView

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
        }
    }
}
like image 347
Reckoner Avatar asked Sep 02 '15 11:09

Reckoner


People also ask

How to reload UITableView?

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.

What is the use of Tableview reloadData property?

reloadData()Reloads the rows and sections of the table view.


1 Answers

Swift 3

NSIndexSet is nothing special

tableView.reloadSections([1, 2, 3], with: .none)

It's just an array. Crazy.

like image 169
Joe Susnick Avatar answered Oct 13 '22 01:10

Joe Susnick