views:

48

answers:

1

I am creating a UIView dynamically and adding a scrollview in it. What I want is to create mutiple scrollviews and add them by using SWITCH Case.

I am passing an integer value called num on IBAction of a button on UIView. and calling the function to create a scrollview.

-(IBAction) button1pressed{
    num = 1;
    NSLog(@"value %d",num);
}

I have 6 IBActions like this with different values of num from 1 to 6. I want to Switch the value of num.

-(void)add_scrollview{
    Switch(num) {
        Case:1 {
            NSLog(@"case 1 executed");              
            break;      
        }
        Case:2 {
            NSLog(@"case 2 executed");
            break;
        } 
        Case :3 {
            NSLog(@"case 3 executed");
            break;
        }
        default:{
            break;
        }
    }
}

every time i click a button, it takes its respective "num" value and performs the switch. But, when i click the another button,it is not switching the value of num. It takes num's previous value.

A: 

case and switch should both be lower case. And the correct syntax is

case 1: {
}

not

case:1{
}

If it still doesnt work i would add an argument to your method with the num instead of having it as a property.

-(void)add_scrollviewWithId:(int) id;
Erik