gpt4 book ai didi

iOS,发送到实例的无法识别的选择器?

转载 作者:可可西里 更新时间:2023-11-01 03:46:56 24 4
gpt4 key购买 nike

我有一个带有导入的自定义 actionBar 的主屏幕。我在一个单独的 .xib 文件中创建了这个 actionBar,其中包含一个 .m 和 .h 文件。

我在我的 actionBar.m 的 viewDidLoad 中做了一些图形设置,比如 backgroundColor 和其他一些东西。

我在这个 actionBar 上也有一个按钮,我用通常链接按钮的方式链接了一个 IBAction

我像这样将我的 actionBar 加载到我的主屏幕中:

ActionBarWithLogoff *actionBar = [[ActionBarWithLogoff alloc] initWithNibName:@"ActionBarWithLogoff" bundle:nil];
[topBar addSubview:actionBar.view];
[actionBar release];

我的 actionBar.h:

- (IBAction)ActionBarLogoff:(id)sender;

我的 actionBars.m 的方法:

-(void) ActionBarLogoff:(UIButton *)sender
{
NSLog(@"!!!!!!!!!!ActionBarLogoff");
}

这是我的错误钢化图片,当我点击按钮时出现以下错误:

2014-01-27 13:52:21.856 GB_Mobil_DK[2954:60b] -[__NSArrayM ActionBarLogoff:]: unrecognized selector sent to instance 0x1656d880 2014-01-27 13:52:21.858 GB_Mobil_DK[2954:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM ActionBarLogoff:]: unrecognized selector sent to instance 0x1656d880' * First throw call stack: (0x2f94be83 0x39ca86c7 0x2f94f7b7 0x2f94e0af 0x2f89cdc8 0x32104da3 0x32104d3f 0x32104d13 0x320f0743 0x3210475b 0x32104425 0x320ff451 0x320d4d79 0x320d3569 0x2f916f1f 0x2f9163e7 0x2f914bd7 0x2f87f471 0x2f87f253 0x345b92eb 0x32134845 0x97985 0x3a1a1ab7) libc++abi.dylib: terminating with uncaught exception of type NSException

谁能告诉我为什么?最重要的是能帮我解决这个问题^^?

最佳答案

您正在释放 actionBar 实例并仅保留其 view。如果 actionBar 实例是按钮操作的响应者,则按钮单击消息将发送到已删除的实例。您应该保留 actionBar 实例。一种方法是将其设为 ivar 或 retain 属性。

看起来您正在为自定义 View 创建 UIViewController。相反,您可以只创建一个带有 XIB 的自定义 UIView

编辑

声明保留属性,

@property (nonatomic, retain) ActionBarWithLogoff *actionBar;

只需声明为ivar,

@interface YourViewController: UIViewController {
ActionBarWithLogoff *actionBar;
}

dealloc方法中,

-(void) dealloc {
//...

[actionBar release];

//...
}

希望对您有所帮助!

关于iOS,发送到实例的无法识别的选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21381641/

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