【问题标题】:Adding a UIPickerView to a UITableView cell将 UIPickerView 添加到 UITableView 单元格
【发布时间】:2011-03-16 11:33:42
【问题描述】:

我正在尝试在表格视图中的一行中添加一个pickerView,但这样做之后,我看到的只是单元格内的一个黑色矩形。

- (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];
    }
}

我真的不知道如何解决这个问题。 谁能帮帮我?

【问题讨论】:

  • 单元格的大小是否适合容纳pickerView?
  • 你不需要设置选择器视图的一些属性,以便它知道要显示什么吗?尝试将 UIPickerView 替换为 UIDatePicker 子类,这样您就知道它肯定有一些内容。
  • 非常感谢。 UIDatePicker 有效。

标签: objective-c xcode uitableview uipickerview


【解决方案1】:

这可能会有所帮助:DateCell with TableViewController

【讨论】:

  • 上帝保佑你 buffer_overflow... 我在谷歌上搜索了好几个小时才找到这个答案。这个例子正是我所需要的......
  • 在苹果 DateCell 示例中遇到问题...只需将所有标签替换为文本字段并添加一些文本字段。打开日期选择器后没有保留文本。当cellforrowatindex:[tableview endupdate]之后调用的方法时如何在文本字段中保留文本
猜你喜欢
  • 1970-01-01
  • 2011-08-17
  • 2015-04-10
  • 2014-01-24
  • 2011-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多