我有这段代码用于显示登录对话框/发布到用户墙上:
_posting = YES;
// If we're not logged in, log in first...
if (![_session isConnected]) {
self.loginDialog = nil;
loginDialog = [[FBLoginDialog alloc] init];
[_loginDialog show];
}
// If we have a session and a name, post to the wall!
else if (_facebookName != nil) {
[self postToWall];
}
// Otherwise, we don't have a name yet, just wait for that to come through.
如果我将这段代码连接到一个按钮,它就可以工作。但是,当我将它放在以下方法中时:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
NSLog(@"No");
}
else
{
_posting = YES;
// If we're not logged in, log in first...
if (![_session isConnected]) {
self.loginDialog = nil;
_loginDialog = [[FBLoginDialog alloc] init];
[_loginDialog show];
}
// If we have a session and a name, post to the wall!
else if (_facebookName != nil) {
[self postToWall];
}
// Otherwise, we don't have a name yet, just wait for that to come through.
}
}
它不起作用..
谁能解释一下为什么会这样?当我说它不起作用时,我的意思是对话框在关闭之前非常短暂地显示。该应用程序不会崩溃。
最佳答案
等待 1 秒不是解决方案,也不能真正解决问题。
问题是你听:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
应该是:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
因为在 clickedButtonAtIndex
函数中 View 没有关闭,这可能会导致问题。
编辑: 为了让它在 iOS 4 中工作,将你的 facebook 登录调用添加到一个方法中,并在 didDismissWithButtonIndex 中调用以下函数:
[self performSelectorOnMainThread:@selector(facebookOpenAction) withObject:nil waitUntilDone:NO];
关于objective-c - Facebook 登录对话框不适用于 UIAlertView,但适用于 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7309289/