UIView setDelegate:]: unrecognized selector sent to instance
Asked Answered
P

1

0

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:]: unrecognized selector sent to instance

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 (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

@interface 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];

can somebody please help.

Thanks

Planck answered 9/11, 2015 at 9:9 Comment(1)
You want to use to set self as the delegate of self? I think you need to rethink that...Cassius
A
0
[(FullVC *)self setDelegate:self];

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];

also in 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];
     * }
     */

}
Agleam answered 9/11, 2015 at 9:36 Comment(1)
Thanks for the response. It resolved my error of unrecognized selector, however, I am still not able to get the values from the delegate method. I am trying to share the title and url values from scrollViewInit method in fullVC controller with menuComponent object.Planck

© 2022 - 2024 — McMap. All rights reserved.