Change UITextField text right before editing when using custom UITableViewCell
Date : March 29 2020, 07:55 AM
this one helps. I think your solution (decoupling the FRC during editing) may be a little drastic and could have unforeseen effects. Here are a couple of alternative suggestions. I am assuming the problem is caused by the table reloading the row you are editing once you have finished editing the first field in the cell. Don't store the currency symbol in your model, add it to the displayed text in cellForRowAtIndexPath, if the text field is not editing. When your textfield begins editing, set its text to the value directly from the model. You don't have to do anything in end editing since the reload will add the currency symbol back on for you. If you dont want to change the model, you can do something similar anyway - in cellForRowAtIndexPath remove the currency symbol if the cell is editing. Store the index path of the currently editing row and conditionally ignore changes to this row in the FRC delegate method.
|
cellForRowAtIndexPath returns null when there's text in the custom UITableViewCell's UITextField
Date : March 29 2020, 07:55 AM
wish of those help There's nothing wrong with the above code. I created a test project, inserted this QuestionCell (complete with UITextField and UILabel objects) and your tableView:cellForRowAtIndexPath, and everything is fine. The UITableView method cellForRowAtIndexPath only returns nil if the cell has scrolled off the screen (and that's expected behavior). But with these six cells present, I iterated through the table's `cellForRowAtIndexPath and everything was fine, regardless if I've entered text or not.
|
Swift: retrieving text from a UITextField in a custom UITableViewCell and putting it in an array
Tag : ios , By : firebasket
Date : March 29 2020, 07:55 AM
This might help you There is a problem with your approach if the number of rows in your table exceeds the number that can fit on screen. In that case, the cells that scroll off-screen will be re-used, and the contents of the nameInput textField will be lost. If you can be sure that this will never happen, use the following code (in the method that handles button taps) to compose your array: var arrayOfNames : [String] = [String]()
for var i = 0; i<self.arrayOfPeople.count; i++ {
let indexPath = NSIndexPath(forRow:i, inSection:0)
let cell : EditingCell? = self.tableView.cellForRowAtIndexPath(indexPath) as EditingCell?
if let item = cell?.nameInput.text {
arrayOfNames.append(item)
}
}
println("\(arrayOfNames)")
var arrayOfNames : [String] = [String]()
var rowBeingEdited : Int? = nil
cell.nameInput.text = "" // just in case cells are re-used, this clears the old value
cell.nameInput.tag = indexPath.row
cell.nameInput.delegate = self
func textFieldDidEndEditing(textField: UITextField) {
let row = textField.tag
if row >= arrayOfNames.count {
for var addRow = arrayOfNames.count; addRow <= row; addRow++ {
arrayOfNames.append("") // this adds blank rows in case the user skips rows
}
}
arrayOfNames[row] = textField.text
rowBeingEdited = nil
}
func textFieldDidBeginEditing(textField: UITextField) {
rowBeingEdited = textField.tag
}
if let row = rowBeingEdited {
let indexPath = NSIndexPath(forRow:row, inSection:0)
let cell : EditingTableViewCell? = self.tableView.cellForRowAtIndexPath(indexPath) as EditingTableViewCell?
cell?.nameTextField.resignFirstResponder()
}
|
UITextfield text inside UITableViewCell disappearing on scroll
Tag : ios , By : user179190
Date : March 29 2020, 07:55 AM
Hope that helps Your code in cellForRowAtIndexPath is fine (subject to clarifying which version of dequeueReusableCellWithIdentifier you want to use). Your problem lies in the for loop where you try to save the values. If you debug this for loop, you will find that cell is nil for any rows which are no longer on screen. You need to find a way to save the values for each row before (or as soon as) it is scrolled off screen. To do that, use the tableView delegate method: - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
Giving a UITextField, in a custom UITableViewCell, the proper text color when the cell is highlighted/selected
Date : March 29 2020, 07:55 AM
|