2013-12-17 49 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); 
} 
相關問題