我剛剛開始iOS開發,並試圖製作一個簡單的應用程序,需要在EST輸入時間,然後輸出PST和CST。我已經獲得了視圖控制器設置,但是我實際顯示時間的功能只會讓我的標籤消失。這是該函數的代碼。執行此代碼時,爲什麼我的標籤消失?
- (IBAction)buttonPress {
NSDateFormatter *date = [[NSDateFormatter alloc] init];
[date setDateFormat:@"hh:mm a"];
[date setDateStyle:NSDateFormatterNoStyle];
[date setTimeStyle:NSDateFormatterShortStyle];
NSDate *estTime = [date dateFromString:self.estText.text];
[date setDateFormat:@"hh:mm a zzz"];
self.pstText.text = [date stringFromDate:estTime];
[date setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CST"]];
self.cstText.text = [date stringFromDate:estTime];
}
is self.estText.text empty?或者那裏有什麼文字?因爲如果使用dateFromString解析失敗,則所有字符串都將爲空 – JeanLuc
否,應該在按下按鈕時從文本字段獲取輸入。 – chaselivingston