1

我想从包含方法列表的其他类创建一个按钮,但是当我单击该按钮时发生错误。

XCode 错误 Kevin MACHADO thedjnivek

类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];
}

我不知道我能做什么。错误信息不是很准确..

4

1 回答 1

2

对于 ClassB 和 ClassC 初始化,如果不调用 super 或为其赋值,则无法返回 self。比如self = [超级初始化]。

于 2013-11-10T16:12:24.580 回答