0

这是我的代码

int indiceCorrente=0; intdifferenza=delegate.reader.feedItems.count;

while(variable!=0){
switch(variable){

case 1: ----
case 2: ----


default: { 

                NSMutableIndexSet *add=[[[NSMutableIndexSet alloc]init] autorelease];
                [add addIndex:indiceCorrente];
                [add addIndex:indiceCorrente+1];
                [add addIndex:indiceCorrente+2];
                [self aggiungiElementoArrayLettura:add];





                //[page addObject:@"makeLayout3"];
                NSMutableArray *pagina=[[NSMutableArray alloc]init];

                indiceCorrente=indiceCorrente+1;
                [pagina addObject:indiceCorrente]; <------ EXC_BAD_ACCESS WHY????
                indiceCorrente=indiceCorrente+1;
                [pagina addObject:indiceCorrente];
                indiceCorrente=indiceCorrente+1;
                [pagina addObject:indiceCorrente];


                [pages addObject:pagina];

            }
}
}
4

1 回答 1

2

您不能将原始类型(int、float、double ...)添加到 Foundation 集合类中。您只能添加对象。当您尝试添加一个 int 时,它被转换为一个指针 (id),并且数组试图保留它。尝试将您的整数包装在一个 NSNumber 中。那看起来像

[pagina addObject:@(indiceCorrente)];

或者

[pagina addObject:[NSNumber numberWithInt:indiceCorrente]];
于 2013-07-14T22:14:06.450 回答