ios - 处理两个登录按钮

标签 ios objective-c facebook-graph-api twitter

我的应用程序有一个登录屏幕,它使用 Facebook 登录和 Twitter 登录。我希望将其设置为如果使用 Facebook,则通过 Facebook 保存用户数据,如果使用 Twitter,则使用 Twitter 信息。

目前我只是想单独为个人资料图像做一个 if 语句,但它似乎并没有按照我想要的方式工作......我正在使用 UIButton 进行 Twitter 登录,以及 FBLoginView 内置类用于 Facebook 登录的 Facebook SDK。这是我的 LoginViewController.m 中 if 语句的代码片段:

- (void)profilePictureChoose:(id)sender{
    if (sender == TWLoginButton){
        theprofilepicture = twitterprofPicture;
    }
    else if(sender == FBLoginButton){
        theprofilepicture = profPicture;
    }
}

我将 FB 登录按钮与 FBLoginButton 属性链接在一起,Twitter 的 UIButton 与属性 TWLoginButton 相链接。这两个属性保存在我的LoginViewController.h中:

@property (weak, nonatomic) IBOutlet FBLoginView *FBLoginButton;
@property (strong, nonatomic) IBOutlet UIButton *TWLoginButton;

我在同一个 .h 文件中也有个人资料图片的这两个属性:

@property (nonatomic)  UIImage *profPicture;
@property (nonatomic)  UIImage *twitterprofPicture;

theprofilepicture 作为我用来从任何 Controller 访问图片的变量。

我不确定如何让 if 语句正确检查单击了哪个按钮。如果有人能帮助我,我将不胜感激

最佳答案

简单地给按钮一个标签怎么样?

 FBLoginButton.tag = 1;
 TWLoginButton.tag = 2;

然后修改头像方法如下:

- (void)profilePictureChoose:(id)sender{
    if (sender.tag == 1){
        //Facebook button
        theprofilepicture = profPicture;
    }
    else if(sender.tag == 2){
        //Twitter button
        theprofilepicture = twitterprofPicture;
    }
}

试试这个,然后告诉我这是否对您有帮助,或者结果如何。

关于ios - 处理两个登录按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31274268/

相关文章:

ios - 以编程方式定位 UITableView

iphone - Objective-C block 停止 UIGestureRecognizer

ios - 委托(delegate)优势

ios - 使用 CAKeyframeAnimation 动画图层位置

ios - 项目之间的碰撞不起作用

ios - 带有 UIWebPaginationModeLeftToRight 的 UIWebView 背景颜色始终为白色

objective-c - init方法中的(id)是什么意思?

JavaScript Facebook 图形 API

php - 分享照片时 Facebook 不显示缩略图

子域上的 Facebook 应用程序 : Site URL vs App Domains