您好我正在學習如何在Objective-C中編寫代碼。我想將我的視圖中的文本字段的值存儲在數組中:iPhone App - NSArray問題
NSArray* answers = [NSArray arrayWithObjects:fluidIntake.text, sleepQuality.text, sleepQuantity.text, mentalRecovery.text,
physicalRecovery.text, pretrainingEnergy.text, muscleSoreness.text, generalFatigue.text, nil];
這可能嗎?如果不是有存儲多個文本框的值,而無需將它們分配給一個NSString變量的任何清潔的方式..
更新:
這裏是我的視圖控制器的功能:
-(IBAction)postData:(id)sender{
diary = [[PersonalDiary alloc]init];
NSArray* answers = [NSArray arrayWithObjects:fluidIntake.text, sleepQuality.text, sleepQuantity.text, mentalRecovery.text,
physicalRecovery.text, pretrainingEnergy.text, muscleSoreness.text, generalFatigue.text, nil];
[diary post:answers to: @"http://www.abcdefg.com/test.php"];
}
它在按下按鈕時觸發。它應該將輸入到文本字段中的8個值存儲在一個NSArray中,並將其傳遞給我的Model類中的一個函數,該函數在一分鐘內嘗試打印數組中的第一個元素(即第一個文本字段值):
-(void) post:(NSArray*) ans to:(NSString*) link{
NSLog(@"%@", ans[0]);
}
但它沒有,它只是打印:PersonalDiary [37114:207] __NSArrayI
您在此期間發佈了更多代碼;我已經刪除了我的答案,因爲它不再有用。 @Joe和@Grady Player的答案非常好。 – fzwo