Two way binding for UIButton in Swift - ios

I'm new to RXSwift. I have UITableViewCell, which has a button. I need to change button state once I click on select all button which is outside of the tableview. I'm changing view model value but UI is not getting updated. Following way I'm binding, how to bind it two ways?
var isSelectedAttendee: Variable<Bool>
cellViewModel?.isSelectedAttendee.asObservable().bind(to: selectButton.rx.isSelected).disposed(by: disposeBag)
Its not duplicated, simple button binding I know but in my case button is inside UITableViewCell. I have tried with different solutions but it didnt solve my problem.

Have a read of this it is, the author has already answered this
https://github.com/ReactiveX/RxSwift/issues/606

Related

Can I choose only portion of a row in UITableView to be clickable(selectable) in Swift?

So I have a table in the accordion style. When a row is clicked, five radio buttons are displayed. Then, users should be able to click on those buttons. It successfully displays the buttons, but when the buttons are clicked, instead of highlighting the selected button, it shrinks the row itself. I think this is probably because I implemented each set of the label part and the option part as a single row, just in different UIViews. I believe clicking on the view that contains buttons is overridden by clicking on the row(label + options). Its really hard to explain, but I think a solution could be restricting selectrow action of the table to only certain portion of the row.
Is there a way I could achieve this? If I cannnot, is there other ways to implement the accordion table to be used as I described?
I am having a really hard time trying to explain this. If you have any questions, please let me know.
table
As per my understanding you van give a try to below steps:
Disable the row selection so that you can avoid row selection. Usecell.selectionStyle = .none
Secondly for your button in row set the IBAction in controller class and in Storyboard connect those actions to specific buttons.

Swift - Stepper in TableViewCell - Action not Responding

Another Swift beginner here. I have a Stepper in a TableView cell which needs to update a label in the same cell. I got part of the way there by asking another question and I received a great answer here: https://stackoverflow.com/a/42877313/3692615.
I think I understand how the code is supposed to work, and my label is updating with the initial value, but unfortunately the stepper action doesn't seem to be connected properly.
I have tried:
Making sure I do not have redundant outlets in the connections inspector
Clean/Build project
Delete all outlets completely and reconnect
Tried changing the sender on the stepper action from UIStepper to AnyObject
I'm running out of ideas. Here is a screenshot of the connections inspector.
Here is the logic. Its basically a model class at the top. Then the outlets along with a property 'buyStat' to hold the current data source item and to update the stepper and label when buyStat is set. That's all working, but the stepper action below it is not. I can't get "stepper working" to print.
Then if it helps, here is my ViewController class
If anyone notices anything or has another idea for me to troubleshoot it would be appreciated. Thanks.
You've disabled the user interaction in your cell for row at index method:
cell.isUserInteractionEnabled = false;
You should remove this line.

How to Use Custom UIButton in UITableViewCell?

I am trying to figure out the best way to apply UIButtons in tableViewCell, I've used tag method. like cell.customButton.tag = indexPath.row, then giving it a target.
But it din't work fine for me if the tableViewCell has may things to show with the same button in all the cells.
There are two options to show the title of the button , just like if we follow a user and unfollow, so after deleting or clicking on any button , it changes the title of some other button also , So, tag method isn't a good option I guess.. Any help would be appreciated.. Thanks!
Using a protocol in a custom table view cell class is what i would suggest:
check out this gitHub commit or download zip for the full project
Adding a Subclass and protocol to a UITableViewCell
I shall have this in the form of an answer later. let me know if you have any questions about the project

Adding a custom control to a nib file

I just discovered that there is no checkbox control in ios. I have found several resources that explain how a custom checkbox could be made. My question is how can I place a custom checkbox control on to a content view . Should I just put a view control in that specific position and then programmatically add the custom control to the view. I wanted to know what is the most common way to accomplish this ?
Checkboxes are mostly for OSX.
On iOS equivalents you can use UISwitch, or use a UIButton and set its state (highlighted, selected, ..) depending on the user selection.
If you absolutely want a checkbox, here is a guide showing how to do it. Seems nice, but I haven't tried it.
http://x-code-tutorials.com/2013/04/09/ios-xcode-checkbox-uibutton/

Outlet Collection Event

I am creating a settings menu and wanted to implement functionality so that when a user toggles any of the switches, it automatically saves their selection in my sqllite database.
I was thinking about putting each element into an outlet collection, iterating over each element, and adding each event to the same function.
Is there an easier way to do this or is that about it?
Thanks!
I'd put it in a tableview.
Then each cell manages its own UISwitch. The UISwitch also talks back to the cell.
Then in the cell you can call back to the table view controller to update it (with the row index) when the switch is updated.

Resources