Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法从UiAlertAction传递参数_Ios_Objective C_Memory_Increment - Fatal编程技术网

Ios 无法从UiAlertAction传递参数

Ios 无法从UiAlertAction传递参数,ios,objective-c,memory,increment,Ios,Objective C,Memory,Increment,我有一个名为MapLayer的自定义NSObject和一个MapLayers的NSMuttableArray,创造性地命名为LayerMuttableArray。按下按钮后,我安装了一个控制器。我使用我的MapLayer列表填充此警报,如下所示: __block NSInteger *n; n = 0; for (MapLayer *m in layersMutableArray) { UIAlertAction *newAction = [UIAlert

我有一个名为MapLayer的自定义NSObject和一个MapLayers的NSMuttableArray,创造性地命名为LayerMuttableArray。按下按钮后,我安装了一个控制器。我使用我的MapLayer列表填充此警报,如下所示:

    __block NSInteger *n;
    n = 0;
    for (MapLayer *m in layersMutableArray) {
        UIAlertAction *newAction = [UIAlertAction actionWithTitle:m.sLayerName style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            MapLayer *ml = layersMutableArray[(int)n];
            curLayer = ml;
            [self loadSpecificLayer];
            n++;
        }];
        [layerSelectionAlertView addAction:newAction];
    }
现在,所有这些都很好。我的AlertView中显示了所有正确的内容


问题是:当我单击一个“层”(UIAlertAction)并调用loadSpecficLayer方法时,它总是重新加载我的第一层。我认为我在内存分配和int(创造性地命名为n)方面做了一些不正确的事情,所以它总是被记为0而不是递增,但我不确定。我尝试过各种类型的数字(NSInteger、int)、施法和其他技巧。非常感谢任何帮助

不要使用
n
。不需要。简单地做:

for (MapLayer *m in layersMutableArray) {
    UIAlertAction *newAction = [UIAlertAction actionWithTitle:m.sLayerName style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        curLayer = m;
        [self loadSpecificLayer];
    }];
    [layerSelectionAlertView addAction:newAction];
}

或者,将
n
的增量移动到块外部。

n
在块运行之前不会递增。你需要把它移到块外,进入循环体。没错,Josh,但我认为rmaddy发现了更大的问题,那就是我可笑的没有注意到我已经从迭代中得到了我的层,所以我不需要使用任何整数来再次得到它哈哈哈