我有一个SQL DB,其中包含每天开放日/小时的商店。我计算今天的日期,并希望在自定义单元格中拥有属性值。
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd"];
int day = [[dateFormatter stringFromDate:[NSDate date]] intValue];
switch (day) {
case 1:
openingsDag = @"open_ma";
break;
case 2:
openingsDag = @"open_di";
break;
case 3:
openingsDag = @"open_woe";
break;
case 4:
openingsDag = @"open_do";
break;
case 5:
openingsDag = @"open_vr";
break;
case 6:
openingsDag = @"open_za";
break;
case 7:
openingsDag = @"open_zo";
break;
default:
break;
}
在cellForRowAtIndexPath中,我将属性值分配给mutablearray中的标签:
cell.naamLabel.text = [[winkelArray objectAtIndex:indexPath.row] naam];
cell.openingsLabel.text = [[winkelArray objectAtIndex:indexPath.row] openingsDag];
这似乎不起作用,我已经尝试了其他几种方法(stringWithFormat,cell.openingsLabel而不是cell.openingsLabel.text,...)来获取标签中的数据,但似乎无法使其正确
答案 0 :(得分:1)
我计算这一天的方法是正确的,但我的返回类型不是......
-(NSString*)berekenOpeningdag:(Winkel*)w {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ee"];
int day = [[dateFormatter stringFromDate:[NSDate date]] intValue];
NSString *openingsUrenReturn = @"";
switch (day) {
case 1:
openingsUrenReturn = w.open_ma;
break;
case 2:
openingsUrenReturn = w.open_di;
break;
case 3:
openingsUrenReturn = w.open_woe;
break;
case 4:
openingsUrenReturn = w.open_do;
break;
case 5:
openingsUrenReturn = w.open_vr;
break;
case 6:
openingsUrenReturn = w.open_za;
break;
case 7:
openingsUrenReturn = w.open_zo;
break;
default:
break;
}
return openingsUrenReturn;
在那里,我回答了我自己的问题!
答案 1 :(得分:0)
检查您的日期格式。 “dd”为您提供月的日期。查看您的switch语句,您希望周的那一天。该日期格式字符串将是“ee”。