iphone - 使用NSInvocation的:恒定值
-
18-09-2019 - |
题
我处理旧的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等,每一个利用其正确的语法的方式的码。
我有上我打上问号线的问题。
的问题有,我试图分配给arg2的,还没有在OS 2.0中定义的常数。因为一切都与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
不隶属于 StackOverflow