回答
Vasilica Costescu在這裏有上有一個偉大的教程: http://masteringios.com/blog/2013/10/31/ios-7-in-line-uidatepicker/
而對於靜態表: http://masteringios.com/blog/2013/11/18/ios-7-in-line-uidatepicker-part-2/
示例代碼在這裏:https://github.com/costescv/InlineDatePicker
關鍵位是隱藏/顯示方法:
- (void)showDatePickerCell {
self.datePickerIsShowing = YES;
[self.tableView beginUpdates];
[self.tableView endUpdates];
self.datePicker.hidden = NO;
self.datePicker.alpha = 0.0f;
[UIView animateWithDuration:0.25 animations:^{
self.datePicker.alpha = 1.0f;
}];
}
- (void)hideDatePickerCell {
self.datePickerIsShowing = NO;
[self.tableView beginUpdates];
[self.tableView endUpdates];
[UIView animateWithDuration:0.25
animations:^{
self.datePicker.alpha = 0.0f;
}
completion:^(BOOL finished){
self.datePicker.hidden = YES;
}];
}
這的UITableViewDelegate方法將「隱藏」的行通過其高度設置爲0:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && indexPath.row == 4 && self.datePickerIsShowing == NO){
// hide date picker row
return 0.0f;
}
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
您還可以從一個按鈕隱藏/顯示方法或只是在表中選擇行。 (注意:如果其他行中有文本字段,那麼您可能需要在textFieldDidBeginEditing委託方法中隱藏datePicker)。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && indexPath.row == 4) {
if (self.datePickerIsShowing){
[self hideDatePickerCell];
}else {
[self showDatePickerCell];
}
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
編輯:使用比一對夫婦,內聯選擇器視圖的更多的單個表中要小心。我注意到,他們往往從故事板非常緩慢加載:iOS 7 slow to open UITableViewController with UIPickerView
@Antony F你有這段代碼和多個部分的經驗嗎? – davidOhara
@chrizstone - 是的。在我的示例中,第0節的第4行只有一個日期選擇器,但可以在不同的行或節中添加多個日期選擇器。 –
我試過了,但由於某種原因,有時在錯誤的行中顯示錯誤的選擇器... – davidOhara
- 1. 的iOS UIPickerView不顯示
- 2. 加載UITableViewCells不在顯示
- 3. 如何顯示在UITableviewcells
- 4. UIPickerView卡在行之間?
- 5. UITableViewCells之間的透明度
- 6. 一段時間無法掩飾iOS的鍵盤和顯示UIPickerView
- 7. UIPickerView不顯示
- 8. iOS 7 UIPickerView沒有顯示它應該是什麼,iOS 6 UIPickerView的
- 9. 在顯示在UITableViewCells之前調整大小和裁剪圖像
- 10. 延遲一段時間後顯示uipickerview
- 11. 在iOS的uitableview中顯示和隱藏uitableviewcells
- 12. iPhone,顯示包含在UIPickerView
- 13. 刪除UITableViewCells之間的間距
- 14. UIPickerView不會顯示
- 15. UIPickerView顯示爲空
- 16. UIPickerView只顯示questionmarks
- 17. 在cellForRowAtIndexPath之外顯示兩個不同的UITABLEVIEWCELLS
- 18. 如何繪製兩個uitableviewcells之間的連接線ios
- 19. 添加2個UITableviewCells之間UITableViewCells與動畫
- 20. 在同一個iOS視圖中顯示兩個UIPickerView,但值顯示爲問號
- 21. UIPickerView未顯示,並且CLLocationManager未在iOS 8中工作
- 22. UIPickerView不會在IOS顯示用數據7
- 23. 如何在iOS 8/Swift中的UIPickerView中只顯示一行?
- 24. iOS - 顯示在Storyboard中取代鍵盤的UIPIckerView
- 25. 陣列UITableViewCells的在IOS
- 26. UITextField - 在鍵盤和UIPickerView之間切換
- 27. UiDatePicker顯示但不顯示UIPickerView
- 28. UITableViewCells之間只有分隔符
- 29. 刪除UITableViewCells之間的差距
- 30. 刪除UITableView中的UITableViewCells之間的線
有一個回答你的問題在這裏: http://stackoverflow.com/questions/17646351/make-uipickerview-appear-細胞之間觸摸單元格 –