Ios – Reload sections in UITableView

iosobjective cuitableview

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
        }
    }
}

Best Answer

Swift 3

NSIndexSet is nothing special

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

It's just an array. Crazy.