2013-12-17 48 views
1

我要为对象,加上阵列到另一个阵列.. 所以,这就是为什么我doint这样的:到另一个阵列添加数组对象

-(void)compute:(NSMutableArray *)ary completion:(void (^)(void))completion{ 
    int id=0; 
    NSLog(@"Array is%@",ary); 
    NSArray *temp; 
    for(int i=0;i<[ary count];i++){ 
     temp=[ary objectAtIndex:i]; 
     id=[[temp objectAtIndex:4] integerValue]; 
     NSLog(@"temp is%@ %d",temp,id); 
     // [MyAppDelegate.searchResultArray addobject:temp]; 
    } 
    NSLog(@"%@",MyAppDelegate.searchResultArray); 
} 

但在登录我在MYAppDelegate.searchResultArray越来越空。在日志中,我获得了临时值。

回答

0

试试这个...

-(void)compute:(NSMutableArray *)ary completion:(void (^)(void))completion{ 
int id=0; 
NSLog(@"Array is%@",ary); 
NSMutableArray *temp; 
for(int i=0;i<[ary count];i++){ 
temp=[ary objectAtIndex:i]; 
    NSLog(@"string%@",[temp objectAtIndex:8]); 
if(id==[[temp objectAtIndex:4] integerValue]){ 
    NSLog(@"inside"); 
    NSMutableArray *temp1=[[NSMutableArray alloc]init]; 
    temp1=[MyAppDelegate.searchResultArray objectAtIndex:i-1]; 
    NSLog(@"temp1%@",temp1); 
    NSString *tempStr=[[temp1 objectAtIndex:8] stringByAppendingString:[temp objectAtIndex:8]]; 
    NSLog(@"%@",tempStr); 
    [temp1 replaceObjectAtIndex:8 withObject:tempStr]; 
    [MyAppDelegate.searchResultArray replaceObjectAtIndex:i-1 withObject:temp1]; 
} 
else{ 
id=[[temp objectAtIndex:4] integerValue]; 
NSLog(@"temp is%@ %d",temp,id); 
[MyAppDelegate.searchResultArray addObject:temp]; 
} 
} 
NSLog(@"%@",MyAppDelegate.searchResultArray); 
} 
相关问题