1,105,578 Community Members

How do you assign UI Elements to a switch statement?

Member Avatar
pars99
Junior Poster in Training
57 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I want to set a text field to look through a switch statement to find the corresponding case. Can I just do that like this?

switch(textField){
    case 'someCase':
        // do something
        break;
    default:
        // do something else
        break;
}

Considering I already created an outlet for it in the @interface file and have connected a button to this as an action (in the @implementation file).

Member Avatar
ChrisPadgham
Posting Pro in Training
450 posts since Sep 2009
Reputation Points: 113 [?]
Q&As Helped to Solve: 90 [?]
Skill Endorsements: 8 [?]
 
0
 

No switch takes an integer you need if then else if construct

if ([textfield.text isequaltostring:@"someCase"]) {
    // do something
} else if ([textfield.text isequaltostring:@"anotherCase"]) {
    // do something else
} else {
    // do yet another thing
}
Member Avatar
pars99
Junior Poster in Training
57 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

No switch takes an integer you need if then else if construct

Really? I didn't know that. Well, thank you. I guess I better go make those if statements.

Question Answered as of 9 Months Ago by ChrisPadgham
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article