【发布时间】:2013-10-28 19:14:11
【问题描述】:
我有一个分段的 UITableView,其中填充了我的数据库中的数据。数据是 JSON 格式,然后根据一个人的工作班次分成三个 MutableArrays。
NSData *data = [NSData dataWithContentsOfURL:url];
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
ridersInVan = [[NSMutableArray alloc] init];
first = [[NSMutableArray alloc] init];
second = [[NSMutableArray alloc] init];
third = [[NSMutableArray alloc] init];
for (int i=0; i< [json count]; i++)
{
item = json[i];
if ([@"1" isEqual: item[@"watch"]] )
{
[first addObject:item];
} else if ([@"2" isEqual: item[@"watch"]] )
{
[second addObject:item];
} else if ([@"3" isEqual: item[@"watch"]] )
{
[third addObject:item];
}
}
ridersInVan = [NSMutableArray arrayWithObjects:first, second, third, nil];
我已经创建了表格视图并填充了所有内容,但我要做的是根据数组内的一些值设置文本颜色
{
driver = 0;
expiration = "2013-10-08";
greenCard = 1;
id = 5;
name = "greg smith";
paid = 1;
phoneNumber = "123 345-1234";
showNumber = 1;
watch = 3;
}
驱动程序、付费、shownumber 都是 BOOL 的,我如何使用我设置的 bool 值设置文本颜色
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[[ridersInVan objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"name"];
cell.detailTextLabel.text = [[[ridersInVan objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"phoneNumber"];
if (paid == NO && currentDate <= 8)
{
cell.textLabel.textColor = START;
} else if (paid == YES) {
cell.textLabel.textColor = PAID;
isPaid = YES;
} else if (paid == NO && currentDate > 8 && currentDate <= 15)
{
cell.textLabel.textColor = LATE;
isLate = YES;
} else if (paid == NO && currentDate > 15 && currentDate <= 28)
{
cell.textLabel.textColor = AFTER_VAN_DATE;
afterDate = YES;
} else if (paid == NO && currentDate > 28)
{
cell.textLabel.textColor = OFF_OF_VAN;
offOfVan = YES;
}
return cell;
}
我试图将支付的值设置为数组中的支付值。有什么想法吗?
【问题讨论】:
-
您添加了很多代码,但我仍然不了解您的数据模型或您的问题究竟是什么。我建议您将问题精简到重点 - 我有这个数据,我怎么能得到这个 - 这就是我所拥有的,但它却变成了 XX。
标签: ios json uitableview nsarray