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

时间:2014-03-10 13:22:47

标签: ios objective-c unrecognized-selector

我是iOS开发人员的新手,我在尝试将开源轮子旋转项目(https://github.com/funkyboy/How-To-Create-a-Rotating-Wheel-Control-with-UIKit)嵌入我的时候遇到了这个问题。

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

“旋转轮组件”来自原始的开源项目,“情绪轮盘”是我的项目。

以下是项目结构的屏幕截图:

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

这是我改变的部分(主要是在ViewController s中进行的更改):

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

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

我还需要改变什么吗?

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我认为您必须设置SMRotaryWheel类的委托:

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

@interface UCViewController : UIViewController <SMRotryWheelDelegate>


@property (nonatomic, strong) UILabel *valueLabel;

@end

注意:我实际上不知道如何调用代表

然后不要忘记实现委托方法。