我使用此代码实现了类似Facebook的按钮:
FBLikeControl *like = [[FBLikeControl alloc] init];
like.objectID = @"1031992973496678";
[like setFrame:CGRectMake(0, 20, 100, 100)];
[[self view] addSubview:like];
我想按下按钮时按钮会消失,使用以下代码:
[like removeFromSuperview];
我如何检测何时按下了喜欢按钮?
编辑:我目前正在使用此代码来检测何时按下了like按钮,但NSLogs和like按钮的存在表明选择器未被使用:
[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];
}
我尝试用[sender removeFromSuperview];
代替[like removeFromSuperview];
,但无济于事。
答案 0 :(得分:3)
在此处查看FBLikeControl
的文档:https://developers.facebook.com/docs/reference/ios/current/class/FBLikeControl
看起来FBLikeControl
继承自UIControl
并通过UIControlEventValueChanged
事件发送信息。尝试为此事件添加侦听器,然后删除视图:
[likeControl addTarget:self action:@selector(likePressed:) forControlEvents:UIControlEventValueChanged];
// ... then later
-(void)likePressed:(id)sender {
[sender removeFromSuperview];
}
答案 1 :(得分:2)
尝试将UIControlEventValueChanged更改为UIControlEventTouchUpInside