How to get the selected row with M13CheckBox pod.. in Swift - ios

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.

Related

Change Parent Collection View cell background color when select child tableview?

I have the parent custom Collectionviewcell and inside I have the child custom Tableview. When I click table view I need to change the background color of collectionviewcell and tableview row background. I am trying achieve using gesture for tableview. but its not working.
try with protocols
first your tableview inform the collection cell
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
backgroundColor = .red
delegate?.didSelectItem(indexPath: indexPath)
}
then on your collectionView Cell
func didSelectItem(indexPath: IndexPath) {
self.backgroundColor = .blue
}
Why you don't use didSelect of tableView?
Some code should be easy to see how you use gestures.
I have created one main array, inside created another array for table content, and manage selection on tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath).
Please check demo : https://github.com/karan7698007/CollectionViewDemo.git

TableView Cell value mandatory fill check Swift

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

How to update CollectionView with TableView "Did Select Row At" method

I have a ViewController that contains a collectionview and a tableview. I would like to be able to press a row in my tableView and update the collectionView with new images. I'm not sure how I can reference the collectionView in this scenario.
I'm assuming I would have to put some code in my "DidSelectRowAt" method in my tableView, and pass data using dictionaries. Anyone have any idea? thanks!
Try this method and pass your latest dictionary to collectionView Dictionary
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
yourCollectionViewDict = arrDict[indexPath.row]
collectionView.reloadData()
}
Have you tried triggering collectionView.reloadData() from your tableView's didSelectRowAtIndexPath?
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
collectionView.reloadData()
}

How to run a function when tableviewcell is selected (for example, update UIImageView when cell is pressed)

I'm making an app that has a collection table view that when a cell is selected it segues into another view controller with a tableview.
I want to use this tableview to update a UIImageView in my VC. So let say i press "Situps" on the TBC i want the imageview to update to an animation that shows situps. Hope someone can understand what im trying to do, thanks for the help!
The delegate method tableView(_:didSelectRowAt:) is called when a cell is tapped on.
You can insert your logic to either segue to another viewController or update an imageView in the same viewController in this method.
for Swift 3.0:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//your code...
}
Documentation: https://developer.apple.com/reference/uikit/uitableviewdelegate/1614877-tableview
Your problem is quite simple.
use method.
tableView(_:didSelectRowAt:)
then put your method here inside did select and you can navigate to viewcontroller you want to.
You can try this:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as UITableViewCell
//so you can do whatever you want on your cell
}
Yes, you can trigger any action of a cell using the didSelect delegate method of Tableview but...
I think that what you are trying to do is to make an update in one VC from other? is that the case, what you need is to use delegation or NSNotificationCenter to send updates between classes.

I am trying to call the tableview "editActionsForRowAtIndexPath" method in a button action. the editing view is not showing

You can see my code here:
#IBAction func edit(sender: UIButton?) {
let indexPath = NSIndexPath(forRow: 0, inSection: 1)
self.tableView(tableVw, editActionsForRowAtIndexPath: indexPath)
}
It seems to that you miss the key points of UITableView behaviour. Please consider to read official documentation first: https://developer.apple.com/reference/uikit/uitableview
You got it backwards, the
optional func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
function is called by the table view on it's delegate while you are supposed to implement it and return an array of custom actions you want displayed - it's not supposed to be called by you to signal something to the table view.
https://developer.apple.com/reference/uikit/uitableviewdelegate/1614956-tableview

Resources