iphone – calling void function – Education Career Blog

in my app i have this method

 -(void) Setinput:(int)input {
//value declared in .h
      value = input;


    b_do setTitle:@"Do" forState:(UIControlState )UIControlStateNormal;
    b_re setTitle:@"Re" forState:(UIControlState )UIControlStateNormal;
    b_me setTitle:@"Me" forState:(UIControlState )UIControlStateNormal;
    b_fa setTitle:@"Fa" forState:(UIControlState )UIControlStateNormal;
    b_sol setTitle:@"Sol" forState:(UIControlState )UIControlStateNormal;
    b_la setTitle:@"La" forState:(UIControlState )UIControlStateNormal;
    b_ci setTitle:@"Ci" forState:(UIControlState )UIControlStateNormal;
    b_doo setTitle:@"Doo" forState:(UIControlState )UIControlStateNormal;
case 1
    b_do setTitle:@"Doo" forState:(UIControlState )UIControlStateNormal;
    b_re setTitle:@"Ree" forState:(UIControlState )UIControlStateNormal;
    b_me setTitle:@"Mee" forState:(UIControlState )UIControlStateNormal;
    b_fa setTitle:@"Faa" forState:(UIControlState )UIControlStateNormal;
    b_sol setTitle:@"Soll" forState:(UIControlState )UIControlStateNormal;
    b_la setTitle:@"Laa" forState:(UIControlState )UIControlStateNormal;
    b_ci setTitle:@"Cii" forState:(UIControlState )UIControlStateNormal;
    b_doo setTitle:@"Dooo" forState:(UIControlState )UIControlStateNormal;
    case 2;



in the mainviewcontroller when i write this code nothing happen why ?

MainViewController xxx = MainViewController alloc init;
xxx Setinput:0


It’s clear this code was not copy/pasted here as the value = input line is missing a semicolon and this would never compile. Assuming the syntactic issues are just a matter of typos when writing the SO question, the code looks OK. This means some other assumption is breaking down. The most likely false assumptions based on this code snippet are:

  1. variables wired to the UIButtons
  2. variables are UIButtons.
  3. The Setinput: method is being called.

I suspect the buttons are not wired to those variables, but it’s impossible to tell from just this code snippet. I’m curious why the cast to (UIControlState) is there. What happens if you compile without it?

Here’s what you can do to figure it out: click on the line number next to the value = input; line to set a breakpoint there and then “Build & Debug.” When the program gets to the breakpoint, step through the code paying attention to the values of your variables in the variable view. You may have to open up “self” to see them. I suspect the first assumption is false and b_do and friends will be 0x00.

If not, it can also help to show the Type column in the variable view (Run -> Variable View -> Show Type Column) so you can make sure the buttons are UIButton objects as you expect. This verifies the second assumption is true.

If the app never reaches that breakpoint, then the third assumption has failed and the problem is not in this code, but somewhere else.

Except it could be this code. Are you really calling xxx Setinput:0 or are you calling xxx.input=0? Why do I ask? When following Objective-C conventions, classes start with a capital letter, variables and methods start with a lower-case letter, and all three are CamelCased. So, by convention Setinput: should be setInput:. This is important because xxx.input=0 is syntactic sugar for xxx setInput:0. If you don’t follow the capitalization conventions, then the syntactic sugar won’t work as expected.

Leave a Comment