我想从包含方法列表的其他类创建一个按钮,但是当我单击该按钮时发生错误。
类A.h
@interface ClassA : NSObject
+ (UIButton *)addUIButton:(UIView *)view text:(NSString *)string action:(ClassB *)action;
+ (UITextField *)addUITextFieldInto:(UIView *)view text:(NSString *)string;
类A.m
+ (UIButton *)addUIButton:(UIView *)view text:(NSString *)string action:(ClassB *)action {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(45, 60, 200, 50);
[button setTitle:string forState:UIControlStateNormal];
[button addTarget:action.callerMethod
action:action.selector
forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
return button;
}
B类.h
@interface ClassB : NSObject
@property (nonatomic) SEL selector;
@property (nonatomic, retain) id delegate;
@property (nonatomic, retain) ClassC *callerMethod;
- (id)initWithDelegate:(id)delegate;
- (void)setAction;
B类.m
- (id)initWithDelegate:(id)delegate { //Method Edited
self = [super init];
if (self != nil)
{
// your code here
self.delegate = delegate;
self.callerMethod = [[LKMethod alloc] initWithDelegate:self.delegate];
}
return self;
}
- (void)setAction {
self.selector = self.callerMethod.alertview;
}
类C.h
@interface ClassC : NSObject
{
id delegate;
}
@property (nonatomic) SEL alertview;
- (id)initWithDelegate:(id)_delegate;
- (void)alertView;
C类.m
- (id)initWithDelegate:(id)_delegate { //Method Edited
self = [super init];
if (self != nil)
{
// your code here
delegate = _delegate;
self.alertview = @selector(alertView);
}
return self;
}
- (void)alertView {
NSLog(@"alertView");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"title"
message:@"message"
delegate:delegate
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[alert show];
}
我的主要方法
- (void)meth {
ClassB *action = [[ClassB alloc] initWithDelegate:self];
[action setAction];
[ClassA addUIButton:self.view text:@"bigup" action:action];
}
我不知道我能做什么。错误信息不是很准确..