iOS如何复制/引用C-Array?

时间:2013-04-25 10:40:21

标签: ios objective-c arrays

我有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有两种不同的尺寸,我应该怎么做才能复制它?我能做什么才能引用或复制到静态数组?

3 个答案:

答案 0 :(得分:2)

试试这个:

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

- (void) tap
   {
     if( closed ) 
        currentEnv = closedEnv;
     else 
        currentEnv = openEnv;
   }

答案 1 :(得分:1)

只需使用:int ** currentEnv = <the array>

答案 2 :(得分:1)

您已将指针数组声明为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 = openEnvcurrentEnv指向openEnv的元素。