我通过 1 个 IBAction 生成了一些不可变数组,但是当我从同一个类中的另一个 IBAction 引用它们时,我无法检索答案。我在第一个 Action 中创建的部分代码是:
所有数组都在第一个 IBAction
中初始化。这是 vType 的示例:
NSMutableArray *vType = [[NSMutableArray alloc] init];
// Gather components for Value Calculations
//NSLog(@" myInv count(h) = %lu and catDetail count(g) = %lu", (unsigned long)[myInv count], (unsigned long)[catDetail count]);
for (h = 0; h < [myInv count]; h++){
//NSLog(@"vScott objectAtIndex:h = %@ AT %d", [vScott objectAtIndex:h], h);
for (g = 0; g < [catDetail count]; g++){
//NSLog(@"cvScott objectAtIndex:g = %@ AT %d", [cvScott objectAtIndex:g], g);
//NSLog(@"vScott objectAtIndex:h = %@ AT %d", [vScott objectAtIndex:h], h);
if ([[vScott objectAtIndex:h] isEqualToString:[cvScott objectAtIndex:g]]){
[vSerStart insertObject:[cvSerStart objectAtIndex:g] atIndex:h];
[vType insertObject:[cvType objectAtIndex:g] atIndex:h];
[vUnitCost insertObject:[cvFacePrice objectAtIndex:g] atIndex:h];
[vYear insertObject:[cvYear objectAtIndex:g] atIndex:h];
//NSLog(@"vScott (vIndex) / cvScott (cvIndex) = %@ (%d) / %@ (%d)", [vScott objectAtIndex:h], h,[cvScott objectAtIndex:g],g);
//NSLog(@"cvSerStart Object %@ atIndex:p = %d",[cvSerStart objectAtIndex:g], g);
//NSLog(@"cvType Object %@ atIndex:p = %d",[cvType objectAtIndex:g], g);
//NSLog(@"vScott / vSerStart / vType // AT (myInv) Index p = %@ / %@ / %@ // %d", [vScott objectAtIndex:h],[vSerStart objectAtIndex:h], [vType objectAtIndex:h],h);
//NSLog(@"+++++++++++++++++++++++++++++++++++++++++");
//NSLog(@" The value calculation Scott Numbers are:%@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@",[vScott objectAtIndex:h], [vExt objectAtIndex:h], [vSer objectAtIndex:h], [vNew objectAtIndex:h], [vUsed objectAtIndex:h], [vPlate objectAtIndex:h], [vSht objectAtIndex:h], [vSerPrice objectAtIndex:h], [vNewPrice objectAtIndex:h], [vUsedPrice objectAtIndex:h], [vPBPrice objectAtIndex:h], [vShtPrice objectAtIndex:h], [vSerStart objectAtIndex:h],[vType objectAtIndex:h]);
vOutLine = [NSString stringWithFormat"%@, %@, %@, %@, %@, %@, %@, %@, %@, %@, %@, %@, %@, %@, %@, %@", [vScott objectAtIndex:h], [vYear objectAtIndex:h], [vExt objectAtIndex:h], [vType objectAtIndex:h], [vSer objectAtIndex:h],[vNew objectAtIndex:h], [vUsed objectAtIndex:h], [vPlate objectAtIndex:h], [vSht objectAtIndex:h], [vUnitCost objectAtIndex:h], [vSerPrice objectAtIndex:h], [vNewPrice objectAtIndex:h], [vUsedPrice objectAtIndex:h], [vPBPrice objectAtIndex:h], [vShtPrice objectAtIndex:h], [vSerStart objectAtIndex:h]];
//NSLog(@"vOutLine = %@", vOutLine);
NSLog(@"%@",[vType objectAtIndex:h]);
[valueData addObject:vOutLine];
可变数组 (vType) 的结果是:
2014-10-24 23:00:53.233 Stamp Collection[6313:1331161] C
2014-10-24 23:00:53.233 Stamp Collection[6313:1331161] C
2014-10-24 23:00:53.233 Stamp Collection[6313:1331161] C
2014-10-24 23:00:53.233 Stamp Collection[6313:1331161] C
尝试使用存储在同一类中的第二个操作中的值,我正在使用此代码进行测试:
- (IBAction)btnValueCollectionDataTableid)sender {
int k,l,m,n;
NSMutableArray *vType;
//if ([[vScott objectAtIndex:h] isEqualToString:[cvScott objectAtIndex:g]]
for (k = 0; k < [myInv count]; k++){
NSLog(@"%@",[vType objectAtIndex:k]);
//if ([[vType objectAtIndex:k] isEqualToString"C"]){
//convert required elements to Integer
//calculate required elements
//}else{
}
}
这个vType数组的试验结果是:
2014-10-24 23:01:00.634 Stamp Collection[6313:1331161] (null)
2014-10-24 23:01:00.634 Stamp Collection[6313:1331161] (null)
2014-10-24 23:01:00.634 Stamp Collection[6313:1331161] (null)
2014-10-24 23:01:00.634 Stamp Collection[6313:1331161] (null)
我认为一旦在类中初始化一个数组就可以在任何地方使用。我会很感激建议,因为我被困在这里。
NSMutableArrays
被声明为每个方法的本地。如果您想从多个方法访问相同的 NSMutableArray
,请将其作为类的属性(或实例变量)。
您需要阅读变量作用域的基础知识。
关于ios - 2 个按钮操作中的 1 个类中的可变数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26559120/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |