2013-01-27 4 views
0

이것은 배열에서 다른 NSNumbers를 하나의 문자열에 연결하기위한 코드입니다. 그러나 어떤 이유로 나는 시계 영역에서 이상한 결과를 얻습니다. NSLog의 결과는 정상입니다. 어쩌면 당신을 도울 수 있습니까?연결 문자열

for (int i = 0; i < [ViewController sharedInstance].safeZonesUserList.count; i++) { 
    int userIndex = [[[ViewController sharedInstance].safeZonesUserList objectAtIndex:i] intValue]; 
    NSString *arrayValue = [NSString stringWithFormat:@"%d",userIndex]; 
    usersList = [usersList stringByAppendingString:arrayValue]; 
    if (i < ([ViewController sharedInstance].safeZonesUserList.count - 1)) { 
     usersList = [usersList stringByAppendingString:@","]; 
    } 
} 

내 배열은 1 보유, 2,하지만 난 시계 영역에서 얻는 결과는 "1, 2, \ x8c @의 \ X01의 \의 x03206 \"

감사합니다,

답변

0

당신은 한 줄의 코드로 예를 대체 할 수

NSString* usersListAsString = [[ViewController sharedInstance].safeZonesUserList componentsJoinedByString:@","] ; 

componentsJoinedByString이있는 NSArray의 모든 항목의 description의를 가져, 루프 내에서 코드의 첫 번째 두 라인 교체. 그런 다음 description을 NSString 하나에 지정한 문자열 (",")로 결합하여 예제의 3 - 5 행을 대체합니다.

+0

그게 효과가 있습니까? –