2010-05-19 73 views
0

我想比較我的didSelectRowAtIndexPath委託方法中的索引路徑與索引路徑數組。比較循環中的indexPaths iphone

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. 

} 

回答

1

使用NSOrderedSame並沒有指針 - NSComparisonResult就是一個整數:

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

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

在Cocoa API的,也有一些非類類型使用。最重要的是那些來自Foundation data types,其中包括

  • 枚舉
  • 類型定義爲整數類型
  • 結構
1

這只是一個int持有這些值之一:

  • NSOrderedAscending
  • NSOrdered同樣
  • NSOrderedDescending

在你的情況,測試NSOrderedSame

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

雞蛋裏挑骨頭,'NSComparisonResult'是'enum',而不是一個'int'。 – 2010-05-19 14:13:45

+0

不,它不是。 'NSOrdered ...'值是枚舉'_NSComparisonResult'(注意下劃線前綴)的成員,但是'NSComparisonResult'是'NSInteger'的一個typedef,它本身就是一個int類型定義。 – 2010-05-19 14:32:08

+1

道歉,我不知何故忽略了:) *(注意自我:仔細觀察之前挑剔)* – 2010-05-19 14:36:18