dhrm
dhrm

Reputation: 14934

How to update title in section header

I have a UITableView where the title in the header for each section displays a date for the content in the current section -- except when the date is today it displays Today and if the date was yesterday, it displays Yesterday.

As these titles are non-static, they change when a new day comes. In that case, I have to scroll down and up again, to get my title in the header updated.

What is the best approach for getting this header updated after midnight?

Upvotes: 0

Views: 355

Answers (2)

Titouan de Bailleul
Titouan de Bailleul

Reputation: 12949

IMHO I don't think this is good practice to automatically refresh the data after midnight or even to refresh data every now and again. You should just let the user do it whenever he wants and also reload data when the app is launched or when the main window reappears.

If you really need this feature maybe, every time the app is launched, you could calculate the time left until midnight and you use a NSTimer to fire the reload method

timerNoTwo = [NSTimer scheduledTimerWithTimeInterval:secondsUntilMidnight target:self selector:@selector(refreshTableView) userInfo:nil NO];

And then

-(void)refreshTableView{ [tableView reloadData]; }

Upvotes: 2

iDifferent
iDifferent

Reputation: 2200

Probably try [tableView reloadData]; to refresh the table after midnight.

Upvotes: 0

Related Questions