我正在构建基于标记的应用程序,并且想要从每个选项卡调用相同的函数(ViewController
)。无法调用类方法
我试图做下列方式:
#import "optionsMenu.h"
- (IBAction) optionsButton:(id)sender{
UIView *optionsView = [options showOptions:4];
NSLog(@"options view tag %d", optionsView.tag);
}
optionsMenu.h
文件:
#import <UIKit/UIKit.h>
@interface optionsMenu : UIView
- (UIView*) showOptions: (NSInteger) tabNumber;
@end
optionsMenu.m
文件:
@import "optionsMenu.h"
@implementation optionsMenu
- (UIView*) showOptions:(NSInteger) tabNumber{
NSLog(@"show options called");
UIView* optionsView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
optionsView.opaque = NO;
optionsView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
//creating several buttons on optionsView
optionsView.tag = 100;
return optionsView;
}
@end
的结果是,我从来没有“show options called”调试消息,因此optionsView.tag
是alwa ys 0
。
我在做什么错了?
我知道这很可能是一个容易和愚蠢的问题,但我无法自己解决它。
任何反馈意见。
我猜这是Objective-C。下次,请用适当的语言标记您的问题。 – 2013-04-25 10:22:08
'options'是否正确初始化? – 2013-04-25 10:25:38
刚宣布为optionsMenu * options; – 2013-04-25 10:27:16