I tried implementing this guide and impelemented it inside:
let doneItem = UITableViewRowAction(style: .Normal, title: " Done ") { (action, indexPath) -> Void in }
but assigning the 'inputView' is where I'm stuck at.
I tried assigning it to the tableView's input view where in the documentation, it says:
"The value of this read-only property is nil. A responder object that requires a custom view to gather input from the user should redeclare this property as read-write and use it to manage its custom input view."
So I tried to redeclare the inputView for the tableView by following this guide but I don't seem to get anywhere.
Help.
I figured out a workaround. If there is a better way of implementing this, I'd like to know. But if there is anyone who is also looking for this solution, here is how I did it.
I added a UITextView through the interface builder and checked the Hidden attribute in the view category under attribute inspector so that user doesn't activate the textfield by accident. Then:
func datePickerSetupTest() {
let dateView = UIView(frame: CGRectMake(0, 100, 320, 160))
datePicker = UIDatePicker(frame: CGRectMake(0, 0, 320, 160))
datePicker.datePickerMode = .Date
dateView.addSubview(datePicker)
inputTextField.inputView = dateView
let doneButton = UIButton (frame: CGRectMake(100, 100, 100, 44))
doneButton.setTitle("Done", forState: UIControlState.Normal)
doneButton.addTarget(self, action: "datePickerSelected", forControlEvents: UIControlEvents.TouchUpInside)
doneButton.backgroundColor = UIColor .blueColor()
inputTextField.inputAccessoryView = doneButton
}
func datePickerSelected() {
print("selectedRow: \(selectedRow!)")
inputTextField.resignFirstResponder()
}
and inside the UITableViewRowAction:
tableView.editing = false
self.selectedRow = indexPath.row
self.inputTextField.becomeFirstResponder()
I'm using the variable selectedView: Int? to pass the selected row to manipulate the data in that row.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.