質問

3.xのために設計している間、私は古いiPhone OS 2.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を使用できるように

0UITableViewCellStyleDefaultとして定義されます。また、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