0
我有一个在accessoryView位置具有名称和文本字段的表格视图。使用以下UITableViewDelegate方法,我调用onEdit并调用UIPickerView。问题是,如果我有更多的1个单元格,它将只填充最后一个uitextfield中的数据,而不管我点击哪个文本字段。如何让数据进入我正在编辑的文本字段?只在UITableViewCell中的最后一个UITextField中填充数据
def tableView(tableView, cellForRowAtIndexPath: indexPath)
@reuseIdentifier ||= "CELL_IDENTIFIER"
cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) || begin
UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:@reuseIdentifier)
end
picker = UIPickerView.alloc.initWithFrame([[0, self.view.frame.size.height/2 + 50], [self.view.frame.size.width, self.view.frame.size.height]])
picker.delegate = self
picker.showsSelectionIndicator = true
@picker_field = UITextField.alloc.initWithFrame([[200,20],[150,40]])
@picker_field.placeholder = "Choose Location.."
@picker_field.delegate = self
@picker_field.inputView = picker
cell.textLabel.text = @list[indexPath.row]
cell.accessoryView = @picker_field
cell.selectedBackgroundView.backgroundColor = UIColor.redColor
#cell.selectionStyle = UITableViewCellSelectionStyleNone
cell
end
def pickerView(pickerView, numberOfRowsInComponent: component)
@choices_count
end
def pickerView(pickerView, titleForRow: row, forComponent: component)
@choices[row]
end
def pickerView(pickerView, didSelectRow: row, inComponent: component)
@picker_field.text = @choices[row]
@picker_field.resignFirstResponder
end
你正在使用实例变量'@ picer_field'和'@ picker',并且每次tableviewcell都会被渲染时会被调用。这可能不是你想要的! – phoet
我改变了这一点,但它仍然将它添加到列表中的最后一个uitextfield。奇怪的是,如果我将inputView更改为常规键盘,而不是uipickerview,它会将键类型输入到适当的字段中。我相信它对我的upickerview –
有一些帮助,现在你的代码如何? – phoet