UIView setDelegate:]:发送到实例的无法识别的选择器

时间:2015-11-09 09:09:21

标签: objective-c uiview uiviewcontroller delegates subview

我是IOS的新手,并尝试将两个值从UIViewController传递给UIView。我跟着几个例子,一些帖子,试过但仍然没有运气。运行应用程序时出现此错误。错误是..

[MenuComponent setDelegate:]:无法识别的选择器发送到实例

MenuComent是我的UIView。 FullVC是我的UIViewController。

FullVC.h

for (JsonNode personNode : rootNode) {
    if (personNode instanceof ObjectNode) {
       if (personNode.has("showTimes")) {
          ObjectNode object = (ObjectNode) personNode;  
          object.remove("showTimes");
       }
    }
}

@property(nonatomic,assign)id delegate;

@end

FullVC.m

 @class FullVC;
    @protocol MenuComponentDelegate <NSObject>   

    -(void)shareToView:(NSString *)titleString inUrl:(NSString *)urlString;

    @end 
    @interface FullVC:UIViewController<UIScrollViewDelegate,UITextViewDelegate> 

MenuComponent.m

@interface MenuComponent()

@end @implementation MenuComponent

    @interface FullVC () 

    @end
@implementation FullVC

    @synthesize delegate;


    - (void)viewDidLoad
    {
        [super viewDidLoad];
    }

    -(void)scrollViewInit
    {
        [self.delegate shareToView:title.text inUrl:urlString];
    }
 @end

我在这个声明中遇到错误。

[(FullVC *)self setDelegate:self];

有人可以帮忙吗?

由于

1 个答案:

答案 0 :(得分:0)

[(FullVC *)self setDelegate:self];

我认为在这一行中self是MenuComponent类的实例, 你不能简单地将自己的类型改为FullVC,这是错误的。

我没有阅读您的所有代码,或者您可以尝试这个

[(FullVC *)self.nav_controller.topViewController setDelegate:self];

也在FullVC中:

-(void)scrollViewInit
{
    [self.delegate shareToView:title.text inUrl:urlString];
    // you can simply check this delegate respond shareToView:inUrl: or not  
    /**
     * if ([_delegate respondsToSelector:@selector(shareToView:inUrl:)])
     * {
     *     [_delegate shareToView:title.text inUrl:urlString];
     * }
     */

}