小编Kie*_*hon的帖子

设置类属性会产生无法识别的选择器错误

我是目标c和iOS的新手.这是我的第一个应用程序,所以请耐心等待.

我只是试图制作一个页面,其中包含一些从文本文件中动态创建的按钮,这将在webview中打开一个页面.

我的代码基于此:如何在UiButton动作中传递任何类型的参数?

MyButton.h

#import <Foundation/Foundation.h>

@interface MyButton : UIButton
{
    NSString *_linkURL;
}
@property (nonatomic, retain) NSString *linkURL;
@end
Run Code Online (Sandbox Code Playgroud)

MyButton.m

#import "MyButton.h"

@implementation MyButton
@synthesize linkURL = _linkURL;
@end
Run Code Online (Sandbox Code Playgroud)

那么在我的ViewController.m文件中,我正在导入MyButton并尝试使用它来创建将URL作为自己的属性的按钮.

MyButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
[button setLinkURL:URL]; //THIS IS THE LINE THATS GIVING ME THE unrecognized selector at instance error
Run Code Online (Sandbox Code Playgroud)

然后我继续在buttonPressed方法中获取URL但我似乎无法通过这一个错误.我不知道我做错了什么.

objective-c uibutton ios unrecognized-selector

1
推荐指数
1
解决办法
252
查看次数