2011-03-16 174 views
4

我想添加一個pickerView到我的表格視圖中的一行,但做完這些之後,我看到的只是單元格內的一個黑色矩形。添加一個UIPickerView到UITableView單元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *MyIdentifier = @"MyIdentifier"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if(cell == nil) {  
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    pickerView = [[[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200, 300)] autorelease];   
    [cell.contentView addSubview:pickerView]; 
    } 
} 

我真的沒有線索如何解決這個問題。 任何人都可以幫助我嗎?

+1

單元格是否保持pickerView的正確大小? – 2011-03-16 11:39:34

+1

您是否需要設置選取器視圖的某些屬性,以便知道要顯示的內容?嘗試用UIDatePicker子類交換UIPickerView,以便知道它確實獲得了一些內容。 – 2011-03-16 11:40:27

+0

非常感謝。 UIDatePicker的作品。 – steve 2011-03-16 12:43:16

回答

9

可能會有這個幫助:DateCell with TableViewController

+0

上帝保佑你buffer_overflow ...我谷歌搜索了幾個小時,直到我找到了這個答案。這個例子正是我所需要的... – Carlos 2013-02-13 08:22:43

+0

面對蘋果DateCell示例中的問題...只需將所有標籤替換爲文本字段並添加少量文本字段即可。打開日期選擇器後,文本不會保留。當cellforrowatindex:[tableview endupdate]之後調用方法時如何保留文本字段中的文本 – harshit2811 2014-03-20 04:56:51

相關問題