繁体   English   中英

如何将字典索引值列表放入if语句中?

[英]How would I put my list of Dictionary index values in an if statement?

我有一个uitableview,如果单元格在存储在NSdictionary中的索引值列表中,我想将文本灰显。 如您所见,我将要变灰的索引列表存储在nsdictionary中,在该列表中我感到模糊是如何将该列表移至if(condition ???)。

NSDictionary *myIndexList = [[inList objectAtIndex:0] objectForKey:@"myIndex"];
   NSLog( @"data from INDEX !!!!!!!! %@", myIndexList);

   if (indexPath.row == ???myIndexList????) {

       cell.textLabel.textColor = [UIColor lightGrayColor];
   }

非常感谢,希望这个新手问题对您有所帮助。

for(NSString *aKey in myIndexList)
{
    if(indexPath.row == [myIndexList valueForKey:aKey])
    {
         cell.textLabel.textColor = [UIColor lightGrayColor];
    }
}

此代码将检查字典中的所有键,如果特定键的值等于行,它将文本颜色更改为lightGrayColor

现在,如果您只是将myIndexList作为NSArray而不是NSDictionary ,则可以使用以下命令:

for(int n=0; n<[myIndexList count]; n++)
{
    if(indexPath.row == [[myIndexList objectAtIndex:n] integerValue])
    {
         cell.textLabel.textColor = [UIColor lightGrayColor];
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM