我的应用程序有一个登录屏幕,它使用 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/