gpt4 book ai didi

iOS - 将变量分配给 cellForRowAtIndexPath 中对象的属性

转载 作者:行者123 更新时间:2023-11-29 05:01:10 24 4
gpt4 key购买 nike

我有一个 SQL 数据库,其中包含每天营业时间/天数的商店。我计算今天的日期,并希望在自定义单元格中包含属性值。

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 中,我将属性值分配给可变数组中的标签:

cell.naamLabel.text = [[winkelArray objectAtIndex:indexPath.row] naam];
cell.openingsLabel.text = [[winkelArray objectAtIndex:indexPath.row] openingsDag];

这似乎不起作用,我尝试了其他几种方法(stringWithFormat,cell.openingsLabel而不是cell.openingsLabel.text,...)来获取标签中的数据,但似乎无法正确处理.

最佳答案

我计算日期的方法是正确的,但我的返回类型不...

-(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;

在那里,我回答了我自己的问题!

关于iOS - 将变量分配给 cellForRowAtIndexPath 中对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6914630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com