1

私は古いiPhoneOS2.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の両方が好きな方法でコードを作成し、それぞれが適切な構文を使用します。

疑問符でマークした行に問題があります。

問題は、OS2.0で定義されていない定数であるarg2に割り当てようとしていることです。NSInvocationのすべては、コンパイラエラーを回避するために間接的に処理を行うことなので、この定数を間接的に変数に設定するにはどうすればよいですか?ある種のperformSelector「変数に値を割り当てる」...

それは可能ですか?助けてくれてありがとう。

4

2 に答える 2

1

UITableViewCellStyleDefaultは、通常使用する場所ならどこでも0使用できるように定義されています。また、NSInvocationを使用する必要はありません。これにより、次のことが可能になります。0UITableViewCellStyleDefault

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でも動作しますが、非推奨になりました。

于 2010-03-09T04:24:59.087 に答える
1
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  
于 2010-03-09T04:30:39.407 に答える