0

Im a noob to iphone development and I am having trouble implementing an if-statement within the didSelectIndex method of AwesomeMenu. The method fires and returns the value of the index selected, but it doesn't respond when I attempt to use the index in a conditional statement within the method. For example, my log only prints "Select the index : 0", but not "Index 0". This is very frustrating to say the least. Any help is greatly appreciated.

MY CODE:

- (void)AwesomeMenu:(AwesomeMenu *)menu didSelectIndex:(NSInteger)idx{

  if (idx==0) {

    NSLog(@"Index 0"); //Doesn't print

  }else if(idx==1){

    NSLog(@"Index 1"); //Doesn't print

  }else{

      NSLog(@"Else Block test"); //Doesn't print

  } 


NSLog(@"Select the index : %d",idx); //<--This Works.

}
4

3 回答 3

2

The delegate is simply set incorrectly.

The boilerplate code for Awesome Menu includes the NSLog statement that is being called. Your above code is fine. You are simply not setting the delegate for the menu to the appropriate object. As a result, your above code never runs.

If you need assistance in this matter, please post the code demonstrating how you initialize your AwesomeMenu.

In any case, search your entire project for the phrase "Select the index" and you will find the delegate method that is actually being executed instead of your current code.

于 2013-03-13T23:17:10.620 回答
0

You can try:

NSInteger i = 2;
NSInteger j = 2;
if (i == j) { 
 NSLog(@"equal")
}
于 2013-03-13T23:10:02.113 回答
0

There is no problem with your If - else statement. check your (NSInteger)idx closely.

Its working fine

[self AwesomeMenu:nil didSelectIndex:1];

- (void)AwesomeMenu:(id )menu didSelectIndex:(NSInteger)idx{

    if (idx==0) {

        NSLog(@"Index 0"); //Doesn't work

    }else if(idx==1){

        NSLog(@"Index 1"); //Doesn't work

    }

    NSLog(@"Select the index : %d",idx); //<--This Works.

}

Output

Index 1
Select the index : 1
于 2013-03-13T23:11:19.500 回答