문제

나는 오래된 iPhone OS 2.X 프로젝트를 다루고 있으며 3.x를 설계하면서 호환성을 유지하고 싶습니다.

나는 nsinvocation을 사용하고 있습니다. 이와 같은 코드입니다.

NSInvocation* invoc = [NSInvocation invocationWithMethodSignature:
       [cell methodSignatureForSelector:
                                    @selector(initWithStyle:reuseIdentifier:)]];
[invoc setTarget:cell];
[invoc setSelector:@selector(initWithStyle:reuseIdentifier:)];
int arg2 = UITableViewCellStyleDefault;  //????
[invoc setArgument:&arg2 atIndex:2];
[invoc setArgument:&identificadorNormal atIndex:3];
[invoc invoke];

3.0과 2.0이 모두 좋아하는 코드를 갖기 위해 각각의 적절한 구문을 사용합니다.

나는 물음표로 표시된 줄에 문제가 있습니다.

문제는 OS 2.0에서 정의되지 않은 상수 인 Arg2에 할당하려고한다는 것입니다. nsinvocation이있는 모든 것이 컴파일러 오류를 피하기 위해 간접적으로 작업을 수행하는 것이므로,이 상수를 간접적 인 방식으로 변수로 어떻게 설정합니까? 어떤 종류의 performselector "변수에 값을 할당"...

그게 가능합니까? 도움을 주셔서 감사합니다.

도움이 되었습니까?

해결책

UITableViewCellStyleDefault 정의됩니다 0 그래서 당신은 사용할 수 있습니다 0 일반적으로 사용하는 곳 UITableViewCellStyleDefault. 또한 nsinvocation을 사용할 필요가 없습니다.

UITableViewCell *cell = [UITableViewCell alloc];
if ([cell respondsToSelector:@selector(initWithStyle:reuseIdentifier:)])
    cell = [(id)cell initWithStyle:0 reuseIdentifier:reuseIdentifier];
else
    cell = [cell initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier];

-[UITableViewCell initWithFrame:reuseIdentifier:] 여전히 3.x에서 작동 할 것이며, 그것은 단지 더 이상 사용되지 않습니다.

다른 팁

NSInvocation* invoc = [NSInvocation invocationWithMethodSignature:
       [cell methodSignatureForSelector:
                                    @selector(initWithStyle:reuseIdentifier:)]];
[invoc setTarget:cell];
[invoc setSelector:@selector(initWithStyle:reuseIdentifier:)];

int arg2;

#if (__IPHONE_3_0)
arg2 = UITableViewCellStyleDefault;
#else
//add 2.0 related constant here
#endif  

[invoc setArgument:&arg2 atIndex:2];
[invoc setArgument:&identificadorNormal atIndex:3];
[invoc invoke];


#if (__IPHONE_3_0)
arg2 = UITableViewCellStyleDefault;
#endif  
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top