比较循环iphone中的indexPaths

时间:2010-05-19 14:04:08

标签: iphone ipad compare nsindexpath

我试图将didSelectRowAtIndexPath委托方法中的索引路径与索引路径数组进行比较。

for (n=0; n < [tempMutArrray count]; n= n+1){

     NSComparisonResult *result = [indexPath compare:[tempMutArray objectAtIndex:n];

//What I want to do is is write an if statement that executes a certain block of code 
//if the two index paths are equal, but I cant figure out how to work with an 
//NSComparisonResult. 

} 

2 个答案:

答案 0 :(得分:1)

使用NSOrderedSame而没有指针 - NSComparisonResult只是一个整数:

NSComparisonResult result = [indexPath compare:[tempMutArray objectAtIndex:n];

if(result == NSOrderedSame) {
    // do stuff
}

在Cocoa API中,有一些非类型正在使用中。最重要的是来自Foundation data types的内容,其中包括

  • 枚举
  • 整数类型的typedef
  • 结构

答案 1 :(得分:1)

这只是一个包含其中一个值的int:

  • NSOrderedAscending
  • NSOrderedSame
  • NSOrderedDescending

在您的情况下,请测试NSOrderedSame

if (result == NSOrderedSame) {
    ...
}