ios - 2 个按钮操作中的 1 个类中的可变数组
<p><p>我通过 1 个 IBAction 生成了一些不可变数组,但是当我从同一个类中的另一个 IBAction 引用它们时,我无法检索答案。我在第一个 Action 中创建的部分代码是:</p>
<p>所有数组都在第一个 <code>IBAction</code> 中初始化。这是 vType 的示例:</p>
<pre><code>NSMutableArray *vType = [ init];
// Gather components for Value Calculations
//NSLog(@" myInv count(h) = %lu and catDetail count(g) = %lu", (unsigned long), (unsigned long));
for (h = 0; h < ; h++){
//NSLog(@"vScott objectAtIndex:h = %@ AT %d", , h);
for (g = 0; g < ; g++){
//NSLog(@"cvScott objectAtIndex:g = %@ AT %d", , g);
//NSLog(@"vScott objectAtIndex:h = %@ AT %d", , h);
if ([ isEqualToString:]){
atIndex:h];
atIndex:h];
atIndex:h];
atIndex:h];
//NSLog(@"vScott (vIndex) / cvScott (cvIndex) = %@ (%d) / %@ (%d)", , h,,g);
//NSLog(@"cvSerStart Object %@ atIndex:p = %d",, g);
//NSLog(@"cvType Object %@ atIndex:p = %d",, g);
//NSLog(@"vScott / vSerStart / vType // AT (myInv) Index p =%@ / %@ / %@ // %d", ,, ,h);
//NSLog(@"+++++++++++++++++++++++++++++++++++++++++");
//NSLog(@" The value calculation Scott Numbers are:%@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@ * %@",, , , , , , , , , , , , ,);
vOutLine = , , , , ,, , , , , , , , , , ];
//NSLog(@"vOutLine = %@", vOutLine);
NSLog(@"%@",);
;
</code></pre>
<p>可变数组 (vType) 的结果是:</p>
<pre><code>2014-10-24 23:00:53.233 Stamp Collection C
2014-10-24 23:00:53.233 Stamp Collection C
2014-10-24 23:00:53.233 Stamp Collection C
2014-10-24 23:00:53.233 Stamp Collection C
</code></pre>
<hr/>
<p>尝试使用存储在同一类中的第二个操作中的值,我正在使用此代码进行测试:</p>
<pre><code>- (IBAction)btnValueCollectionDataTable:(id)sender {
int k,l,m,n;
NSMutableArray *vType;
//if ([ isEqualToString:]
for (k = 0; k < ; k++){
NSLog(@"%@",);
//if ([ isEqualToString:@"C"]){
//convert required elements to Integer
//calculate required elements
//}else{
}
}
</code></pre>
<p>这个vType数组的试验结果是:</p>
<pre><code>2014-10-24 23:01:00.634 Stamp Collection (null)
2014-10-24 23:01:00.634 Stamp Collection (null)
2014-10-24 23:01:00.634 Stamp Collection (null)
2014-10-24 23:01:00.634 Stamp Collection (null)
</code></pre>
<p>我认为一旦在类中初始化一个数组就可以在任何地方使用。我会很感激建议,因为我被困在这里。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><code>NSMutableArrays</code> 被声明为每个方法的本地。如果您想从多个方法访问相同的 <code>NSMutableArray</code> ,请将其作为类的属性(或实例变量)。 </p>
<p>您需要阅读变量作用域的基础知识。 </p></p>
<p style="font-size: 20px;">关于ios - 2 个按钮操作中的 1 个类中的可变数组,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26559120/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26559120/
</a>
</p>
页:
[1]