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

标签 objective-c if-statement ios

我有一个 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];
    }
}

关于objective-c - 如何将字典索引值列表放入 if 语句中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10806012/

相关文章:

objective-c - "Couldn' t send a valid signature”使用CloudKit时出错

ruby-on-rails - rails : Multiple if conditions in validation

c# - C# 中的 Try-Catch 与 If 性能

ios - 将日期从一种格式转换为其他格式在 objective-c 中返回 nil

ios - 等待响应 Alamofire swift

objective-c - 将 objectAtIndex 的返回值转换到 NSArray 上

iphone - Objective-C : [MyObject alloc] now crashes under iOS SDK 4. 1

php - 如果使用三元运算符,如何修复我的 PHP 内联?

ios - UIAlertView 未在 Monotouch Release 版本中显示

objective-c - 自定义 UIButton 焦点在 tvOS 中无法正常工作