2011-03-16 98 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

相关问题