..................IOS, KVC는 왜 countOf <Key>를 호출하지 않습니다
Environment:OSX10.8, Xcode4.5 Reference: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual /KeyValueCoding/Articles/SearchImplementation.html#//apple_ref/doc/uid /20000955-CJBBBFFA If the countOf method and at least one of the other two possible methods are found, a collection proxy object that responds to all NSArray methods is returned. Each NSArray message sent to the collection proxy object will result in some combination of countOf, objectInAtIndex:, and AtIndexes: messages being sent to the original receiver of valueForKey:.
내 단계 :
1) MyObject.h에서 NSArray* arrs
에 대한 property
을 만듭니다.
2) MyObject.m
@implementation MyObject
- (void)setArrs:(NSArray*)arrs
{ _arrs=arrs; }
- (NSUInteger) countOfArrs
{ NSLog("Im here");
return 0;}
- (id) objectInArrsAtIndex:(NSUInteger)index
{ NSLog(@"objectInArrs");
return nil;
}
@end
3) 테스트 코드
MyObject* obj=[[MyObject alloc] init];
NSArray* arr=[NSarray arrayWithObjects:@"abc",nil];
[obj setArrs:arr];
NSLog(@"%d",[[obj valueForKey:@"arrs"]count]);
NSLog(@"%@",[[obj valueForKey:@"arrs"] objectobjectAtIndex:0])
나의 질문 : 나는 countOfArrs
자동 objectInArrsAtIndex:
, 그러나 호출 할 것으로 예상
, 그것은하지 않았다. 모두 정상적인 NSArray를 반환하고, 카운트 수량을 1 및 'abc'로 보여줍니다.
도움이되는 샘플을 찾지 못했거나 의사가하는 말을 잘못 이해했을 수 있습니다. 그렇습니까?
제 탕 언어가 영어가 아니므로 야심적인 문제를 만들지 않았 으면합니다.
작동합니다. http://www.cocoabuilder.com/archive/cocoa/236041-kvc-array-proxy-objects.html 마침내, 아무도 그에게 대답하지 않았다. .. 아마 나는 같은 결과를 가질 것이다 ??? – MarcusHe