djinne95
djinne95

Reputation: 375

How to detect Facebook like button being clicked?

I've implemented a Facebook like button using this code:

FBLikeControl *like = [[FBLikeControl alloc] init];
like.objectID = @"1031992973496678";
[like setFrame:CGRectMake(0, 20, 100, 100)];
[[self view] addSubview:like];

I would like to have the button disappear when it is pressed, using this code:

[like removeFromSuperview];

How would I detect when the like button is pressed?

Edit: I am currently using this code to detect when the like button is being pressed, but the NSLogs and like button's presence indicate the selector is not being used:

[like addTarget:self action:@selector(likePressed:) forControlEvents:UIControlEventValueChanged];
[[self view] addSubview:like];



- (void) likePressed:(id)sender {
NSLog(@"GG, like was pressed!");
[sender removeFromSuperview];
[likeText removeFromSuperview];
}

I have tried substituting [sender removeFromSuperview]; with [like removeFromSuperview];, to no avail.

Upvotes: 1

Views: 736

Answers (2)

user3647894
user3647894

Reputation: 599

Try changing UIControlEventValueChanged to UIControlEventTouchUpInside

Upvotes: 2

Aaron Wojnowski
Aaron Wojnowski

Reputation: 6480

Check out the docs for FBLikeControl here: https://developers.facebook.com/docs/reference/ios/current/class/FBLikeControl

It looks like the FBLikeControl inherits from UIControl and sends information through the UIControlEventValueChanged event. Try add a listener for this event then remove the view:

[likeControl addTarget:self action:@selector(likePressed:) forControlEvents:UIControlEventValueChanged];

// ... then later

-(void)likePressed:(id)sender {

    [sender removeFromSuperview];    

}

Upvotes: 3

Related Questions