Male and female radio button with label in cell iOS swift
Problem:
I want to add radio button in cell with values as Male and female.And i want to add an action that will show only if male selected then female wants to be unselected.
How can i achieve that?
Solution:
In cell i had the below code.
Code:
cell.maleBtn.isSelected = true
if let detail = newdetails {
if let gender = detail.thegender, gender == "male" {
cell.maleBtn.isSelected = true
cell.femaleBtn.isSelected = false
} else if let gender = detail.thegender, gender == "female" {
cell.femaleBtn.isSelected = true
cell.maleBtn.isSelected = false
}
}
The above code will get the last selected value and set in cell
Code:
cell.lblMale.rx.tapGesture()
.when(.recognized) // This is important!
.subscribe(onNext: { [weak self] _ in
guard let self = self else { return }
self.view?.endEditing(true)
newdetails?.Gender = "Male"
self.DetailTV.reloadSections(IndexSet(arrayLiteral: section.gender), with: .none)
}).disposed(by: cell.disposebag)
while label tapped then action will be updated in the above code because if user tap on the label then it will be worked
Code:
cell.maleBtn.rx.tap.asDriver()
.drive(onNext: { [weak self] in
self?.view?.endEditing(true)
self?.newdetails?.Gender = "Male"
self?.DetailTV.reloadSections(IndexSet(arrayLiteral: section.gender), with: .none)
}).disposed(by: cell.disposebag)
Male button action is added above
Code:
cell.lblFeMale.rx.tapGesture()
.when(.recognized) // This is important!
.subscribe(onNext: { [weak self] _ in
guard let self = self else { return }
self.view?.endEditing(true)
self.newdetails?.Gender = "Female"
self. DetailTV.reloadSections(IndexSet(arrayLiteral: section.gender), with: .none)
}).disposed(by: cell.disposebag)
while female label tapped then action will be updated in the above code because if user tap on the label then it will be worked
Code:
cell.femaleBtn.rx.tap.asDriver()
.drive(onNext: { [weak self] in
self?.view?.endEditing(true)
self?.newdetails?.Gender = "Female"
self?.DetailTV.reloadSections(IndexSet(arrayLiteral: section.gender), with: .none)
}).disposed(by: cell.disposebag)
FeMale button action is added above
Comments
Post a Comment