方法我看到這個帖子:How to sort an NSMutableArray of objects by a member of its class, that is an int or float寫作比較:在Objective-C
與此前類似的東西,但我不知道它是如何工作,並希望一些指導。我有一個標記對象的數組,它有一個類型伊娃,取值爲0,1,2。我想要一個複選框,說什麼命令,0,1或2.
我開始關閉的試圖做類似的事情在我自己的方法:
- (NSComparisonResult)Type:(id)otherObject {
if ([self Type] > [otherObject Type]) {
return NSOrderedAscending;
}
else if ([self Type] < [otherObject Type]) {
return NSOrderedDescending;
}
else {
return NSOrderedSame;
}
}
在我的.h文件:
NSInteger _type;
@property NSInteger Type;
我得到了兩個警告:指針和整型(「身份證」之間 有序比較NSInteger') 方法 - 未找到類型(返回類型默認爲'id')
我不明白當你調用sort方法時發生了什麼。謝謝。
爲了查看下面的答案是否在正確的軌道上,查看您的頭文件可能會有所幫助,其中定義了類型。 – deftangel