我有3个带有整数(枚举)的数组:

static int *openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int *closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
int *currentEnv[];

如果用户点击按钮,我希望将currentEnv更改为openEnvclosedEnv
- (void) tap
{
    if( closed ) currentEnv = closedEnv;
    else currentEnv = openEnv;
}

但这会导致构建错误。openEnvclosedEnv具有2个不同的大小,我应该怎么做才能复制它?我该怎么做才能使其引用或复制到其静态数组?

最佳答案

您已经声明了指向int的指针数组。正确的是

static int openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};

(不带星号*)来声明int数组,以及
int *currentEnv;

作为指向int的指针。然后您可以分配currentEnv = openEnv,以便currentEnv指向openEnv的元素。

关于ios - iOS如何复制/引用C-Array?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16212582/

10-12 14:45