根据日期时间显示 UITableView 附件
所以我有一个 UITableView,我想根据一天中的时间在一行旁边打勾。例如,如果是上午 9:00,我只想检查第一行,等等。
这是我正在使用的代码:
cell.accessoryType = [self setTheAccessaryType:indexPath.row];
这是该方法:
-(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;
}
提前致谢 如果您需要更多信息,请告诉我
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这两种情况下,您都返回 AccessoryNone,也许您想从 if 语句中返回 UITableViewCellAccessoryCheckmark 。
You're returning AccessoryNone in both cases, maybe you wanted to return UITableViewCellAccessoryCheckmark from inside your if statement.