我有一个基本问题,并且是 Objective-C 的新手。
我有如下代码,有很多“如果”条件。我想增强这段代码。
我不能使用'switch-case',因为它(aNode)不返回整数。
它返回一个对象指针 (CC3Node*)。
有人可以建议我如何减少这些“if”语句并巧妙地增强此代码吗?
-(void) nodeSelected: (CC3Node*) aNode byTouchEvent: (uint) touchType at: (CGPoint) touchPoint {
if ( aNode == [self getNodeNamed: A_NODE] )
{
keyid =103;
}
if ( aNode == [self getNodeNamed: B_NODE] )
{
keyid =105;
}
if ( aNode == [self getNodeNamed: C_NODE] )
{
keyid =102;
}
if ( aNode == [self getNodeNamed: D_NODE] )
{
keyid =104;
}
if ( aNode == [self getNodeNamed: E_NODE] )
{
keyid =202;
}
if ( aNode == [self getNodeNamed: F_NODE] )
{
keyid =206;
}
if ( aNode == [self getNodeNamed: G_NODE] )
{
keyid =203;
}
if ( aNode == [self getNodeNamed: H_NODE] )
{
keyid =207;
}
if ( aNode == [self getNodeNamed: I_NODE] )
{
keyid =208;
}
if ( aNode == [self getNodeNamed: J_NODE] )
{
keyid =401;
}
if ( aNode == [self getNodeNamed: K_NODE] )
{
keyid =402;
}
if ( aNode == [self getNodeNamed: L_NODE])
{
keyid =404;
}
等等....