首先,我想爲我在編程方面的知識缺乏而感到抱歉。我正在學習和發現,這個網站對我來說是一個巨大的讚美。只有方法執行的最後一行(Objective-C)
我創建了一個程序有三個的UITextField(thePlace,theVerb,theOutput)和兩個UITextView的其中textviews(theOutput)採取從其他的TextView(theTemplate)文本之一,並替換某些字符串與在輸入的文本文本框。
當我點擊一個按鈕時,它會觸發下面列出的方法createStory。這工作正常,但有一個例外。輸出中的文本僅將字符串「數字」更改爲文本字段中的文本。但是,如果我更改方法中的替換'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