2012-04-13 75 views
0

我有一個UITextView用來顯示我的選擇從UIPickerView這個項目。我已經可以顯示選擇,但是當我選擇另一個選擇時,它會覆蓋前一個選擇,並且我需要跟蹤所做的所有選擇。如何跟蹤UITextView中UIPickerView的選擇?

這裏是我的代碼:

NSString *msg = [NSString stringWithFormat: @"Você comprou %@ %@ e pagará R$ %.2f.", 
       [quantidade objectAtIndex:[pickerView selectedRowInComponent:1]], 
       [produtos objectAtIndex:[pickerView selectedRowInComponent:0]], total]; 


texto.text = msg; 

任何人都可以幫助???謝謝

回答

0

一個解決方案可能是在您的視圖控制器,一個NSMutableString中創建一個實例變量。然後,每一次,你選擇從您選擇器視圖的新值,只是追加新的選擇在你的字符串,如:

在.H

NSMutableString *mutableStr; 

在.M

// In your init 
mutableStr = [[NSMutableString alloc] initWithString:@""]; 

// When a selection is made 
[mutableStr appendFormat:@"Você comprou %@ %@ e pagará R$ %.2f.", 
       [quantidade objectAtIndex:[pickerView selectedRowInComponent:1]], 
       [produtos objectAtIndex:[pickerView selectedRowInComponent:0]], total];