I want to implement cell value check on tableview cell for specific rows ( only to those fields which are mandatory) so alert generate or print command, cell row background color will be set to red and user must have to fill that values before posting values to Server. Which function I have to use for it to check cell value status? Also I am using sections and rows structure in tableView.
For posting changes to server I am using button. Guidance suggestions required.
1.Save temporary data about cells which have mandatory fields to be filled.
2.Using this data, check whether user filled or not in below method
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
3.Keep updating temporary data whenever user interacts with cells.
Hope this helps.
write your validation check logic code in:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { }
and when you want to check just reload tableview
Related
I'm using leadingSwipeActionsConfigurationForRowAt to detect and process swipes. However, I need to be able to detect when the user started to swipe, but before it completes. The problem is that if I update the table using reloadData() or beginUpdates() / endUpdates() while a cell is being swiped, it resets the cell to the un-swiped position (and I don't like that kind of user experience). I want to be able to delay the cell/data update until the swipe is finished or cancelled.
Even though Andreas' answer is absolutely correct, I found an easier way to do it. Apparently, whenever leadingSwipeActionsConfigurationForRowAt is used, the cell is marked as being edited whenever it starts being swiped. And that allows us to use willBeginEditingRowAt and didEndEditingRowAt on the UITableView, without having to worry about the UITableViewCell
var swipedRow: IndexPath? = nil
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
swipedRow = indexPath
}
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
swipedRow = nil
}
And then you can just check if swipedRow == nil (plus, if it's not nil, you will know the indexPath of the row being swiped)
You could implement willTransition(to:) in the UITableViewCell` to detect a swipe, see:
UITableViewCell documentation
There, just set a flag in the view controller to prevent updates.
You might also need to do something in viewWillDisappear or so, because maybe the transition callbacks are not called under some circumstances.
I'm getting weird behaviour in my TableView
I turned isUserInteractionEnabled on one of my section headers because I need to put a collectionView in it. Before I did anything I noticed that when I tap on that header view (it is a UITableViewCell) it triggers the didSelectRowAt method with the index of a first cell in that section (right below the header). Does anybody know what causes that behaviour and how to turn it off?
Your header sections are part of your UITableView.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
}
In this method indexPath return rows and section, indexPath.section
-> returns section of UitableView, you have tapped and indexPath.row -> returns down of that particular section, tapped.
So this function is going to get called no matter what you do. You
need to override the table view's gesture to avoid this.
Help! I haven't been able to find an answer online. How do you find out the selected row when using the M13CheckBox pod? As there is no delegate method.. from my prototype cell on UIstoryboard it only allows me to reference an action.. any links appreciated..
You don't, if the cell has no other responsibility use the func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { }
when user selects the cell, alternate the button check state.
I'm having a tableview cell with a label, i need to get the values from the labels when the user click on each cell and store it into array according to the indexpath of tableview.
In Swift 4, you can do this
Let YOUR_ARRAY be your string array used to populate Table View, then
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(YOUR_ARRAY[indexPath.row])
}
Get Value from didSelectRowAt
Using cellForRow(at: <#T##IndexPath#>) function it will return a UITableViewCell in selected row.
if you used custom XIB tableview cell means downcast that tableview cell else you can directly access a cell property(label).
I agree with #vadian comment:
You should access your data model array with the [indexPath.row] value and extract the current value of the data there. Don't access the cell directly.
I have two table views containing data, the first one is completely okay. I want to push from this table view to another view to another table view, but I cannot set the rows for it. How can I navigate through a multidimensional array in
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
Basically, my problem is about setting the right text for a row and getting from a multidimensional array :) (P.S. I have a different number of Strings in each subarray)
You just need to check on which tableView you are setting the values.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
if tableView == myFirstTableView {
// put the data for the first tableView
} else {
// put the data for the second tableview
}
}