2015-03-02 46 views
2

我有一個表格視圖控制器,我需要在點擊一個單元格時顯示一個日期&時間選擇器,並在單元格再次點擊時隱藏它。基本上,當你選擇你的開始和結束日期和時間來創建日曆中的新事件時,iPhone具有相同的效果。在UITableViewCell的水龍頭上顯示和隱藏DatePicker

我猜的顯示和隱藏在去下面的方法,但我不能確定什麼走了進去:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {} 

一些示例代碼或鏈接將是巨大的。謝謝!!

回答

0

你可能會發現我的答案在這裏很有用,它描述了你需要做什麼。

Inline UIPicker Implementation

基本上你創建一個包含日期選擇器自定義單元格,可選按鈕。然後在編輯它時在單元格下面添加此單元格,並在完成時將其刪除。所有在鏈接中解釋。

1

創建你想顯示無論你的細胞和選擇器:

----------------------------------- 
cell visible part 
----------------------------------- 
cell invisible part (with picker) 
----------------------------------- 

定義,讓你知道,如果你要顯示整個單元的屬性:

@property (nonatomic) BOOL shouldShowPicker; 

初始化這個屬性(例如viewDidLoad);

self.shouldShowPicker = NO; 

一對夫婦的方法來摸:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if(indexPath.row == 4) { //where your picker row is 
     self.shouldShowPicker = YES; 
      [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
    } 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row == 4 && self.shouldShowPicker) { //where your picker row is 
     return CELL_VISIBLE_PLUS_INVISIBLE_PART; 
    } else if(indexPath.row == 4 && !self.shouldShowPicker) { 
     return return CELL_VISIBLE_PART; 
    } else { 
     return OTHER_CELLS_HEIGHT; 
    } 
} 
相關問題