gpt4 book ai didi

ios - 从包含它的方法的其他类创建按钮

转载 作者:行者123 更新时间:2023-11-29 10:52:30 25 4
gpt4 key购买 nike

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

XCode Error 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;

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

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

最佳答案

对于Class和Class的初始化,不调用super或者赋值是不能返回self的。如self = [super init].

关于ios - 从包含它的方法的其他类创建按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19891568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com