在大韩民国,这是一个不容置疑的问题,但除这里外,我别无处可问。
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.
我试图将案件单独列入一个方法,这是我拥有的:
www.un.org/Depts/DGACM/index_french.htm
#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
www.un.org/Depts/DGACM/index_french.htm
#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
当然,这部法律是不正确的,但这只是我想要得到的蓝图。
问题:
- 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?