gpt4 book ai didi

ios - 单击我的按钮时,无法识别的选择器发送到实例错误

转载 作者:行者123 更新时间:2023-11-29 11:36:48 26 4
gpt4 key购买 nike

<分区>

我花了一天的时间试图弄清楚为什么每当我点击代码中生成的一个按钮时我都会收到这个错误:

-[HomeViewController aMethod:]: unrecognized selector sent to instance 0x102813a00 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeViewController aMethod:]: unrecognized selector sent to instance 0x102813a00' * First throw call stack: (0x184e83164 0x1840cc528 0x184e90628 0x18e7fe188 0x184e88b10 0x184d6dccc 0x18e4725cc 0x18e47254c 0x18e45d0f4 0x18e47a368 0x18eacd5e4 0x18eac8b94 0x18eac8678 0x18eac77d4 0x18e46ce5c 0x18e43de7c 0x18ed9330c 0x18ed95898 0x18ed8e7b0 0x184e2b77c 0x184e2b6fc 0x184e2af84 0x184e28b5c 0x184d48c58 0x186bf4f84 0x18e4a15c4 0x100eb5a20 0x18486856c) libc++abi.dylib: terminating with uncaught exception of type NSException

我是 Objective-C 和 iOS 的新手。我很有可能遗漏了一些简单/基本的东西。

这是创建按钮的代码:

for (int i =0 ; i < numDevices; i++)
{
CBPeripheral* periph = devices[i];
printf("%s%s\n", "Found Devices Name: ", [[periph name] UTF8String] );


//Create button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
[button setTitle:[periph name] forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 480, 100);

//set constraints on button
[button.heightAnchor constraintEqualToConstant:100].active = true;
//[button.widthAnchor constraintEqualToConstant:210].active = true;

//set image
UIImageView* iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"App_Background.png"]];
iv.frame = CGRectMake(0, 0, 480, 100);
[button addSubview:iv];

//Add action event to button
[button addTarget:self action:@selector(Test:) forControlEvents:UIControlEventTouchUpInside];

//add button to stackview
[stackView addArrangedSubview:button];
}

这是点击按钮时应该调用的函数:

    -(IBAction) Test: (id) sender
{
//printf("%s%s\n", "Selected Button: ", [[sender currentTitle] UTF8String]);
}

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