이것은 stackoverflow 내 첫 번째 질문입니다! xcode에서 두 개의 배열을 사용하여 문자열을 뒤집어 쓰려고 시도 중입니다. 인터페이스를 설정하고 버튼, 텍스트 필드 및 레이블이 있습니다. 버튼을 터치하면 텍스트 입력란에 들어가는 내용이 모두 바뀝니다. 나는 코드를 얻었고 그것이 나에게 맞는 것처럼 보였다. 문제는 내가 "HELLO"와 같이 애플리케이션을 테스트 할 때, myArray의 내용은 "H E"이고 reverseArray는 "O L L"이다. 누구 새김 도움 메신저 꽤이 코드 추적과 함께 공급하는 경우 ID가 감사 : 코드 (((여기 입니다 : 두 번째 루프를 들어xcode 배열을 사용하여 문자열을 반전
@interface ViewController()
@end
@implementation ViewController
@synthesize textField,string1,string2,reverseArray,myArray;
@synthesize Label1;
- (IBAction)Reverse:(UIButton *)sender {
reverseArray=[[NSMutableArray alloc]init];
string1=[[NSString alloc]init];
string2=[[NSString alloc]init];
string1=textField.text;
myArray=[[NSMutableArray alloc]init];
for (int i=0; i<=string1.length-1; i++) {
[myArray insertObject:[[NSString alloc] initWithFormat:@"%c",[string1 characterAtIndex:i]] atIndex:i];
}
for (int j=0; j<=myArray.count-1; j++) {
[reverseArray insertObject:[myArray objectAtIndex:myArray.count-1] atIndex:j];
[myArray removeLastObject];
}
NSLog(@"%@",myArray);
NSLog(@"%@",reverseArray);
thx alot brett, 그것은 완벽하게 잘 작동;) –