OK, this is going to be a stupid question but anyway I have nowhere to ask it except here.
I have two buttons and there must be a switch-case statement performed on tapping any of them. Of course I can put this statement in each IBAction code block but this code would look terribly.
I tried to put swith-case into a separate method and this is what I have:
.h file
#import <UIKit/UIKit.h>
@interface AppViewController : UIViewController
{
IBOutlet UILabel *someTextLabel;
NSNumber *current;
}
@property (nonatomic, retain) IBOutlet UILabel *someTextLabel;
@property (nonatomic, retain) NSNumber *current;
- (void) switchMethod;
- (IBAction) pressButtonForward;
- (IBAction) pressButtonBack;
@end
.m file
#import "AppViewController.h"
@implementation AppViewController
@synthesize someTextLabel;
@synthesize current;
current = 0;
- (void) switchMethod:current
{
switch((int)current) {
case 0:
//do something
break;
case 1 :
//do something
break;
//etc
default:
//do something
break;
}
}
- (IBAction) pressButtonBack
{
if((int)current == 0) {
current = 6;
}
else {
current--;
}
//here must be a switchMethod performed
}
- (IBAction) pressButtonForward
{
if((int)current == 6) {
current = 0;
}
else {
current++;
}
//here must be a switchMethod performed
}
//auto-generated code here
@end
Of course this code is incorrect but this is just like a blueprint of what I wanted to get.
Questions:
- What is a correct way of using such switch-case statement as a separate method so that I could call it from IBAction methods?
- How should I cast data types for this code to work, or would it be better to use integer type (for "current" variable) everywhere?