먼저 프로그래밍에 대한 지식 부족에 대해 사과드립니다. 나는 학습의 길에 있으며,이 사이트가 저를 위해 큰 보완이라고 발견했습니다.메서드 실행의 마지막 행만 (Objective-C)
나는 3 개의 UITextField (thePlace, theVerb, theOutput)와 두 개의 UITextView를 가진 프로그램을 만들었고, textviews (theOutput) 중 하나는 다른 textview (theTemplate)의 텍스트를 가져 와서 일부 문자열을 텍스트 필드.
버튼을 클릭하면 아래 나열된 createStory 메소드가 트리거됩니다. 이 예외는 한 가지 예외가 있습니다. 출력의 텍스트는 문자열 'number'를 텍스트 필드의 텍스트로만 변경합니다. 그러나 'place', 'number', 'verb'를 대체 할 메소드의 순서를 변경하면 숫자가 아닌 동사 만 변경됩니다.
분명히 이것은 일종의 쉬운 수정이지만 찾을 수 없습니다. 문제 해결에 도움을 줄 수있는 사람이 있습니까?
- (IBAction)createStory:(id)sender {
theOutput.text=[theTemplate.text stringByReplacingOccurrencesOfString:@"<place>" withString:thePlace.text];
theOutput.text=[theTemplate.text stringByReplacingOccurrencesOfString:@"<verb>" withString:theVerb.text];
theOutput.text=[theTemplate.text stringByReplacingOccurrencesOfString:@"<number>" withString:theNumber.text];
}
많은 감사 // 에밀
고마워요. 그러나 밤의 잠 후 나는 그것을 더 똑똑하게 쓰는 방법을 이해했다. 매번 템플릿의 출력을 변경하는 대신 템플릿에서 처음으로 출력을 변경하고 두 번째로 첫 번째 출력의 출력을 변경하고 두 번째 출력의 세 번째 출력을 변경합니다. – Emil
theOutput.text = [theTemplate.text stringByReplacingOccurrencesOfString : @ ""withString : thePlace.text]; theOutput.text = [theOutput.text stringByReplacingOccurrencesOfString : @ ""withString : theVerb.text]; theOutput.text = [theOutput.text stringByReplacingOccurrencesOfString : @ ""withString : theNumber.text]; –
Emil