UIView setDelegate:]:无法识别的选择器已发送到实例 [英] UIView setDelegate:]: unrecognized selector sent to instance

查看:193
本文介绍了UIView setDelegate:]:无法识别的选择器已发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to IOS, and Trying to pass two values form a UIViewController to a UIView. I followed few examples,some posts, tried and still no luck. I am getting this error while running the application. The error is ..

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

[MenuComponent setDelegate:]: unrecognized selector sent to instance

MenuComent是我的UIView. FullVC是我的UIViewController.

MenuComent is My UIView. FullVC is my UIViewController.

FullVC.h

 @class FullVC;
    @protocol MenuComponentDelegate <NSObject>   

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

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

@property(非原子,分配)ID委托;

@property (nonatomic,assign) id delegate;

@end

FullVC.m

    @interface FullVC () 

    @end
@implementation FullVC

    @synthesize delegate;


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

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

MenuComponent.m

MenuComponent.m

@interface MenuComponent()

@interface MenuComponent()

@end @implementation MenuComponent

@end @implementation MenuComponent

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {

      if ([self.nav_controller.topViewController isKindOfClass:[FullVC class]])
       {
          if (indexPath.row==0)
            {
                [(FullVC *)self setDelegate:self];
            }
       }

    }
    -(void)shareToView:(NSString *)titleString inUrl:(NSString *)urlString
    {
       NSLog(@"title string after passing is: %@", titleString);
       NSLog(@"url string after passing is: %@", urlString);
    }
    @end

我在此声明中遇到了错误.

I am getting error at this statement.

[((FullVC *)self setDelegate:self];

[(FullVC *)self setDelegate:self];

有人可以帮忙吗?

谢谢

推荐答案

[(FullVC *)self setDelegate:self];

我认为这一行self是MenuComponent类的实例, 您不能简单地将self的类型更改为FullVC,这是错误的.

I think in this line self is the instance of MenuComponent class, you can not simply change the type of self to FullVC, it is wrong.

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

I'm not reading all of your code,or you can try this

[(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];
     * }
     */

}

这篇关于UIView setDelegate:]:无法识别的选择器已发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆