ios - 发送到 UIViewController(或协议(protocol))实例的无法识别的选择器?

标签 ios objective-c unrecognized-selector

我对 iOS 开发还很陌生,当我尝试将开源 Wheel Rotating 项目 ( https://github.com/funkyboy/How-To-Create-a-Rotating-Wheel-Control-with-UIKit ) 嵌入到我的项目中时,我遇到了这个问题。

基本上,我把这个开源项目的相关代码文件和 Assets 复制到我的,并做了一些必要的修改,希望它能运行。

“Rotary Wheel Component”来自原始开源项目,“Mood Roulette”是我的项目。

这是项目结构的屏幕截图:

enter image description here

以及堆栈跟踪:

2014-03-10 13:06:12.865 Mood Roulette[13125:60b] cl is 7 | 0.392699, 0.785398, 1.178097
2014-03-10 13:06:12.866 Mood Roulette[13125:60b] -[UCViewController wheelDidChangeValue:]: unrecognized selector sent to instance 0x146d175f0
2014-03-10 13:06:12.869 Mood Roulette[13125:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UCViewController wheelDidChangeValue:]: unrecognized selector sent to instance 0x146d175f0'
*** First throw call stack:
(0x18ba1f09c 0x19799dd78 0x18ba23d14 0x18ba21a7c 0x18b9414ac 0x1000c05fc 0x1000bfb44 0x1000c26f4 0x18e8f42c0 0x18e8f4044 0x18e8fb7dc 0x18e8f8ab0 0x18e96c88c 0x18e9691f0 0x18e9629a0 0x18e8f5530 0x18e8f4720 0x18e9620b0 0x191345128 0x191344c54 0x18b9defc8 0x18b9def28 0x18b9dd14c 0x18b91db38 0x18e9612d4 0x18e95c0e8 0x1000c24b8 0x197f87aa0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

======

错误点在第100行

[self.delegate wheelDidChangeValue:[self getCloveName:currentValue]];

代码:

https://github.com/funkyboy/How-To-Create-a-Rotating-Wheel-Control-with-UIKit/blob/master/RotaryWheelProject/SMRotaryWheel.m

这里是我修改的部分(主要修改在ViewControllers):

UCAppDelegate.h:

#import <UIKit/UIKit.h>

//@class UCViewController;
@interface UCAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
//@property (strong, nonatomic) UCViewController *viewController;

@end

UCAppDelegate.m:

@implementation UCAppDelegate

//@synthesize window;
//@synthesize viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
//    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//    self.window.rootViewController = self.viewController;
//    [self.window makeKeyAndVisible];
    return YES;
}

UCViewController.h

#import <UIKit/UIKit.h>
#import "SMRotaryProtocol.h"

@interface UCViewController : UIViewController


@property (nonatomic, strong) UILabel *valueLabel;

@end

UCViewController.m:

#import "UCViewController.h"
#import "SMRotaryWheel.h"

@interface UCViewController ()

@end

@implementation UCViewController

@synthesize valueLabel;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 350, 120, 30)];
    valueLabel.textAlignment = NSTextAlignmentCenter;
    valueLabel.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:valueLabel];

    SMRotaryWheel *wheel = [[SMRotaryWheel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)
                                                    andDelegate:self
                                                   withSections:8];

    wheel.center = CGPointMake(160, 240);
    [self.view addSubview:wheel];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

该项目将毫无问题地构建,但会留下黑屏并在运行时给出无法识别的选择器错误。

还有什么我还需要改变的吗?

感谢您的帮助。

最佳答案

根据您发布的内容,您的 UCViewController 中没有方法 wheelDidChangeValue: 的实际实现。因此,当在运行时调用该方法时,没有方法可以“捕获”该调用,这会导致您看到的错误。

关于ios - 发送到 UIViewController(或协议(protocol))实例的无法识别的选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22301354/

相关文章:

iphone - 如何在 UIWebView 中加载本地 HTML 文件?

swift - 使用 #selector swift3 时出现 NSInvalidArgument 异常

android - 在移动应用程序上播放受 vimeo 域限制的视频

ios - 在 Iphone App 中使用 Logger 的最佳做法是什么

ios - Physics Body edges IOS8,Sprite Kit

c# - MonoTouch - UIView.Animate 完成回调未在按钮 touchUpInside 委托(delegate)内调用

ios - 判断 UITableView 是否已经滚动到顶部

ios - 如何以一般形式表示 nsstring 以进行搜索或比较?

ios - iCarousel - numberOfItemsInCarousel : unrecognized selector sent to instance

uitableview - 使用 UITableViewCell AccessoriesView 成员的两个 UIButton 制作自定义 UIView 会导致无法识别的选择器发送到实例错误