mack mack - 9 days ago 7
Swift Question

how to send radio button selection to server

I have some text fields, and when user enter any value i will send all that to server by pressing save button. Here is that code :

@IBAction func addUserBtnPressed(sender: AnyObject) {
if validateProfileData() {
profileData.FirstName = self.data["FirstName"]!
profileData.LastName = self.data["LastName"]!
profileData.DateOfBirth = self.data["DateOfBirth"]!
profileData.Email = self.data["Email"]!
profileData.Mobile = self.data["Mobile"]!

profileData.Country = self.data["Country"]!
profileData.State = self.data["State"]!
profileData.City = self.data["City"]!

let toViewController = NextVC
}
}


But I have two radio button for select the gender like male or female. I'm using this library for select the gender Radiobutton . But I don't know how to send that to server by pressing the save button. Please help me out..!

Answer

for your male female button that i created you have to done country your self beacuse of i dont have time for that. i m busy in my work.

@IBOutlet var btn_male: UIButton! // create outlet for radio button
@IBOutlet var btn_female: UIButton! 

var gender : NSString = ""
@IBAction func btn_male_female_click(sender: UIButton) {
        switch sender.tag {
        case 10:
            //male select
            if (sender.selected == true) {
                sender.selected = false;
                btn_male.selected = true;
                btn_female.selected = false;
                gender = "1"
            }else{
                sender.selected = true;
                btn_male.selected = false;
                btn_female.selected = true;
                gender = "2"
            }
            break;
        case 20:
           //female select
            if (sender.selected == true) {
                sender.selected = false;
                btn_female.selected = true;

                btn_male.selected = false;
                gender = "2"
            }else{
                sender.selected = true;
                btn_female.selected = false;
                btn_male.selected = true;
                gender = "1"
            }

            break;
        default:
            break;
        }
    }


override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(true)
    if profileData.Gender .isEmpty {

    }else{
        if profileData.Gender == "1"{
            self.btn_male.selected = true
        }else{
            self.btn_female.selected = true
        }

    }
}

var data:[String:String]{

     return ["FirstName":firstName.textVal,"LastName":lastName.textVal,"DateOfBirth":dateOfBirth.textVal,"Email":emailId.textVal,"Mobile":mobile.textVal,"Gender":gender as String,"Country":country.textVal,"State":state.textVal,"City":city.textVal]
}

in your code

@IBAction func addUserBtnPressed(sender: AnyObject) {


            profileData.FirstName = self.data["FirstName"]!
            profileData.LastName = self.data["LastName"]!
            profileData.DateOfBirth = self.data["DateOfBirth"]!
            profileData.Email = self.data["Email"]!
            profileData.Mobile = self.data["Mobile"]!

            if btn_male.selected == true {
                profileData.Gender = "1"
            }else{
                profileData.Gender = "2"
            }

            profileData.Country = self.data["Country"]!
            profileData.State = self.data["State"]!
            profileData.City = self.data["City"]!


            let toViewController = NextVC
            toViewController!.transitioningDelegate = self.transitionManager
            presentViewController(toViewController!, animated: true, completion: nil)

    }

YOUR DESIGN