So I have a UITableView, and I want to put a check next to a row depending on the time of day. For example, if its 9:00 AM, I want a check on the first row only, etc.
Here is the code I’m working with:
cell.accessoryType = [self setTheAccessaryType:indexPath.row];
Here is that method:
-(UITableViewCellAccessoryType )setTheAccessaryType:(int)indexPath {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setDateFormat:@"HH"];
int hour = [[dateFormatter stringFromDate:[NSDate date]] intValue];
[dateFormatter setDateFormat:@"mm"];
int minute = [[dateFormatter stringFromDate:[NSDate date]] intValue];
[dateFormatter release];
if (indexPath == 0 && hour >= 8 && minute >= 20) {
NSLog(@"in here");
return UITableViewCellAccessoryNone;
}
return UITableViewCellAccessoryNone;
}
Thanks in advance
Let me know if you need more information
You’re returning AccessoryNone in both cases, maybe you wanted to return UITableViewCellAccessoryCheckmark from inside your if statement.