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