1

メソッドのリストを含む他のクラスからボタンを作成したいのですが、ボタンをクリックするとエラーが発生します。

XCode エラー Kevin MACHADO thedjnivek

ClassA.h

@interface ClassA : NSObject

+ (UIButton *)addUIButton:(UIView *)view text:(NSString *)string action:(ClassB *)action;
+ (UITextField *)addUITextFieldInto:(UIView *)view text:(NSString *)string;

ClassA.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;
}

ClassB.h

@interface ClassB : NSObject 

@property (nonatomic) SEL selector;
@property (nonatomic, retain) id delegate;
@property (nonatomic, retain) ClassC *callerMethod;

- (id)initWithDelegate:(id)delegate;
- (void)setAction;

ClassB.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;
}

ClassC.h

@interface ClassC : NSObject
{
    id delegate;
}

@property (nonatomic) SEL alertview;

- (id)initWithDelegate:(id)_delegate;
- (void)alertView;

ClassC.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 = [super init] など。

于 2013-11-10T16:12:24.580 に答える