我正在开发QRCode应用程序,我遇到了一些启用条形码符号的问题。 我有一个数组,其中我从websrvice数据响应获得所有条形码符号,需要作为启用。 我应用静态代码如下,它适用于我。 但我想让它充满活力。以下是我的代码:
请帮我制作,动态。我尝试了很多方法但没有得到适当的解决方案
创建了两个数组:
NSMutableArray *enableSymbologies = [[[NSMutableArray alloc] init] autorelease]; // Data from webservice response
NSMutableArray *symbologiesToSet = [[[NSMutableArray alloc] init] autorelease]; // for enabling barcode symbology
for (int i =0 ; i < [enableSymbologies count] ; i ++)
{
if([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code39"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_39]];
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code93"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_93]];
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code25I"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_25]];
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code25S"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_25]];
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code128"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_128]];
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"QR"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_QR]];
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"EAN+UPC"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_EANUPC]];
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"PDF"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_PDF]];
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"CodaBar"])
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_CODABAR]];
}
else
{
[symbologiesToSet addObject:[NSNumber numberWithInt:MWB_CODE_MASK_QR]];
}
}
//我的静态方法,我想让它变得动态
for (int i = 0; i < [symbologiesToSet count]; i++)
{
if([symbologiesToSet count] == 1)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue]);
}
else if([symbologiesToSet count] == 2)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue] | [[symbologiesToSet objectAtIndex:1] integerValue]);
}
else if([symbologiesToSet count] == 3)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue] | [[symbologiesToSet objectAtIndex:1] integerValue] | [[symbologiesToSet objectAtIndex:2] integerValue]);
}
else if([symbologiesToSet count] == 4)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue] | [[symbologiesToSet objectAtIndex:1] integerValue] | [[symbologiesToSet objectAtIndex:2] integerValue] | [[symbologiesToSet objectAtIndex:3] integerValue]);
}
else if([symbologiesToSet count] == 5)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue] | [[symbologiesToSet objectAtIndex:1] integerValue] | [[symbologiesToSet objectAtIndex:2] integerValue] | [[symbologiesToSet objectAtIndex:3] integerValue] | [[symbologiesToSet objectAtIndex:4] integerValue]);
}
else if([symbologiesToSet count] == 6)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue] | [[symbologiesToSet objectAtIndex:1] integerValue] | [[symbologiesToSet objectAtIndex:2] integerValue] | [[symbologiesToSet objectAtIndex:3] integerValue] | [[symbologiesToSet objectAtIndex:4] integerValue] | [[symbologiesToSet objectAtIndex:5] integerValue]);
}
else if([symbologiesToSet count] == 7)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue] | [[symbologiesToSet objectAtIndex:1] integerValue] | [[symbologiesToSet objectAtIndex:2] integerValue] | [[symbologiesToSet objectAtIndex:3] integerValue] | [[symbologiesToSet objectAtIndex:4] integerValue] | [[symbologiesToSet objectAtIndex:5] integerValue] | [[symbologiesToSet objectAtIndex:6] integerValue]);
}
else if([symbologiesToSet count] == 8)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue] | [[symbologiesToSet objectAtIndex:1] integerValue] | [[symbologiesToSet objectAtIndex:2] integerValue] | [[symbologiesToSet objectAtIndex:3] integerValue] | [[symbologiesToSet objectAtIndex:4] integerValue] | [[symbologiesToSet objectAtIndex:5] integerValue] | [[symbologiesToSet objectAtIndex:6] integerValue] | [[symbologiesToSet objectAtIndex:7] integerValue]);
}
else if([symbologiesToSet count] == 9)
{
MWB_setActiveCodes([[symbologiesToSet objectAtIndex:0] integerValue] | [[symbologiesToSet objectAtIndex:1] integerValue] | [[symbologiesToSet objectAtIndex:2] integerValue] | [[symbologiesToSet objectAtIndex:3] integerValue] | [[symbologiesToSet objectAtIndex:4] integerValue] | [[symbologiesToSet objectAtIndex:5] integerValue] | [[symbologiesToSet objectAtIndex:6] integerValue] | [[symbologiesToSet objectAtIndex:7] integerValue] | [[symbologiesToSet objectAtIndex:8] integerValue]);
}
}
#define MWB_CODE_MASK_NONE 0x00000000u
#define MWB_CODE_MASK_QR 0x00000001u
#define MWB_CODE_MASK_DM 0x00000002u
#define MWB_CODE_MASK_RSS 0x00000004u
#define MWB_CODE_MASK_39 0x00000008u
#define MWB_CODE_MASK_EANUPC 0x00000010u
#define MWB_CODE_MASK_128 0x00000020u
#define MWB_CODE_MASK_PDF 0x00000040u
#define MWB_CODE_MASK_AZTEC 0x00000080u
#define MWB_CODE_MASK_25 0x00000100u
#define MWB_CODE_MASK_93 0x00000200u
#define MWB_CODE_MASK_CODABAR 0x00000400u
#define MWB_CODE_MASK_ALL 0x00ffffffu
答案 0 :(得分:0)
我得到了解决方案。这是......
if(curEvent.enablescanning == 1)
{
if([enableSymbologies count] == 0)
{
MWB_setActiveCodes(MWB_CODE_MASK_QR);
}
else
{
int globalSelectedTypes = 0;
for (int i =0 ; i < [enableSymbologies count] ; i++)
{
if([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code39"])
{
globalSelectedTypes = globalSelectedTypes + MWB_CODE_MASK_39;
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code93"])
{
globalSelectedTypes = globalSelectedTypes + MWB_CODE_MASK_93;
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code25I"] || [[enableSymbologies objectAtIndex:i] isEqualToString:@"Code25S"])
{
globalSelectedTypes = globalSelectedTypes + MWB_CODE_MASK_25;
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"Code128"])
{
globalSelectedTypes = globalSelectedTypes + MWB_CODE_MASK_128;
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"QR"])
{
globalSelectedTypes = globalSelectedTypes + MWB_CODE_MASK_QR;
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"EAN+UPC"])
{
globalSelectedTypes = globalSelectedTypes + MWB_CODE_MASK_EANUPC;
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"PDF"])
{
globalSelectedTypes = globalSelectedTypes + MWB_CODE_MASK_PDF;
}
else if ([[enableSymbologies objectAtIndex:i] isEqualToString:@"CodaBar"])
{
globalSelectedTypes = globalSelectedTypes + MWB_CODE_MASK_CODABAR;
}
}
MWB_setActiveCodes(globalSelectedTypes);
}
}