if语句在单元格中显示图像
我想在我的单元格中显示图像,但前提是JSON
数据的值为1(只有0或1可能) 也许如果JSON
数据的值为0显示不同的图像,所以每个细胞可以显示2个不同的图像。
到目前为止的问题是,单元格包含图像,而不是数据的值是什么JSON
数据是。if语句在单元格中显示图像
到目前为止的代码:
NSArray *arrayOfEntry = [allDataDictionary objectForKey:@"notities"];
for (NSDictionary *diction in arrayOfEntry)
{
sonResults = [allDataDictionary objectForKey:@"notities"];
NSMutableString *checkvink = [diction objectForKey:@"not_verwerkt"];
if(![checkvink isEqual: @"1"])
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"vink" ofType:@"png"];
imageData = [NSData dataWithData:[NSData dataWithContentsOfFile:path]];
}
}
然后我告诉像这样
UIImage *imageLoad = [[UIImage alloc] initWithData:imageData];
cell.notAfbeel.image = imageLoad;
像我在做什么错?
编辑:完整的cellForRowAtIndexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *Cellidentifier = @"Cell";
NotitieCell *cell = [tableView dequeueReusableCellWithIdentifier:Cellidentifier];
if(!cell)
{
cell = [[NotitieCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cellidentifier];
}
NSDictionary *appsdict = [jsonResults objectAtIndex:indexPath.row];
UIImage *imageLoad = [[UIImage alloc] initWithData:imageData];
cell.notAfbeel.image = imageLoad;
return cell;
}
JSON数据
{
"notities": [{
"not_nr": "1191555",
"not_tijd": "12:29:54",
"not_type": "0",
"not_behandeld": "Richard",
"not_bestemd": "Richard",
"not_contactpers": "Maarten",
"not_prioriteit": "1",
"not_onderwerp": "Printer staat er nog steeds in",
"not_naam": "apple store",
"not_woonpl": "Amsterdam",
"not_land": "NL",
"not_verwerkt": "0"
}
}
问题是imageData
是一个实例变量。您正在为整个对象实例设置其值,而不仅仅是单元格。所以,她调用了cellForRowAtIndexPath
,它将这个变量值放在所有单元格中。
转变你的arrayOfEntry
在属性并假设它完全在你的tableView显示,我们可以把您的cellForRowAtIndexPath
这样的:
也许它不是根据数据的最佳答案,但仅仅是给你一个想法,让你可以适应它。
谢谢你这里面为我工作!对不起已故的响应(流感有我)。我删除了自己。因为我已经说前面的代码。 – SpeedfreakR
也许你应该使用isEqualToString
代替isEqual
,因为你在该行比较的NSString值:
if(![checkvink isEqualToString: @"1"])
难以忍受的伎俩 – SpeedfreakR
哼哼......你可以发布你的JSON文件的一部分@SpeedfreakR吗?也许这将有助于有点 –
JSON是没有问题的(我猜是因为我可以证明与JSON数据标签,但我会张贴。 – SpeedfreakR
发表您的整个的cellForRowAtIndexPath方法 –
发布的cellForRowAtIndexPath – SpeedfreakR
只是语句之前分配的imageData中的cellForRowAtIndexPath本身 “的UIImage * imageLoad = [[UIImage的页头] initWithData:为imageData]。” 对不起延迟伙计 –