I am trying to do something I thought would be relatively simple and get the current day of the week, then make some checks against that day when buttons are tapped. to get the day of the week I have used the following code in my viewDidLoad method:
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents =
[gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:today];
NSInteger day = [weekdayComponents day];
NSInteger weekday = [weekdayComponents weekday];
The code returns me two NSIntegers which are the current day of the week and the current day of the month, which is what I wanted. I now want to have a series of buttons, which when tapped displays a certain webpage in a UIWebView depending on the day of the week.
I was hoping to do a simple:
-(IBAction) btnClicked
{
if (weekday == 1)
{
//DO SOMETHING HERE
{
}
But I can't seem to get access to the 'weekday' NSInteger which was created in the viewDidLoad method. Im sure I am missing something very simple. Any advice?