我有3个带有整数(枚举)的数组:
static int *openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int *closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
int *currentEnv[];
如果用户点击按钮,我希望currentEnv
更改为openEnv
或closedEnv
- (void) tap
{
if( closed ) currentEnv = closedEnv;
else currentEnv = openEnv;
}
但这会产生构建错误。
openEnv
和closedEnv
有两种不同的尺寸,我应该怎么做才能复制它?我能做什么才能引用或复制到静态数组?
答案 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 = openEnv
,currentEnv
指向openEnv
的元素。