Question

I have a FBLogin (Facebook SDK) button I am using in a view being replicated throughout many of my view controllers. It seems I cannot set a UIView as a delegate to the Facebook SDK, so I am trying to create a seperate ViewController to handle the delegate functions of the Facebook SDK.

Header file:

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>

@class AppDelegate, FBDelegateViewController;
@interface UserView : UIView {

    AppDelegate *appDelegate;

    IBOutlet UIView *contentView;
    IBOutlet UIImageView *userImage;
    IBOutlet UILabel *firstName;
    FBDelegateViewController *fbDelegate;
    IBOutlet FBLoginView *FacebookLogin;

}

@property (nonatomic, strong) IBOutlet UIView *contentView;
@property (nonatomic, strong) IBOutlet UILabel *firstName;
@property (nonatomic, strong) AppDelegate *appDelegate;
@property (nonatomic, strong) FBDelegateViewController *fbDelegate;

Currently in my implementation I am doing the following:

#import "UserView.h"
#import "AppDelegate.h"
#import "FBDelegateViewController.h"
#import <FacebookSDK/FacebookSDK.h>

@implementation UserView

@synthesize contentView, firstName, appDelegate, fbDelegate;

- (void)awakeFromNib {

    fbDelegate = [[FBDelegateViewController alloc] init];
    appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    [[NSBundle mainBundle] loadNibNamed:@"UserView" owner:self options:nil];
    [self addSubview:self.contentView];
    [userImage.layer setCornerRadius:21.5];

    [FacebookLogin setDelegate:fbDelegate];

}

@end

The application crashes with the following:

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setDelegate:]: unrecognized selector sent to instance 0xa5e4f80'*

In interface builder the UIView that contains the FBLogin item is set.

I also tried delegation with the UIView as well, but it looks like a UIView cannot be a delegate for a FBLogin?

Sorry, new territory here. Typically have used the associated view controller as a delegate - but want to understand external delegation.

Was it helpful?

Solution

It seems I cannot set a UIView as a delegate to the Facebook SDK, so I am trying to create a seperate ViewController to handle the delegate functions of the Facebook SDK.

This assumption is false, any NSObject can be set as the delegate as long as it implements the FBLoginViewDelegate protocol

This can be done like this:

@interface UserView : UIView <FBLoginViewDelegate> {

After you do this, you can set this view as the delegate!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top