• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iOS:Google+ 按钮在 XIB 文件中不起作用?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 23:34:16 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我问 iOS: Sign In with Google button昨天还在挣扎。我得到的答案帮助我弄清楚 GooglePlus.bundle 导入不正确。

现在我被困在我通过 XIB 文件创建的按钮没有显示在页面上的部分。

我做了什么?
我根据这个 gist 添加了一个新按钮,并验证是否一切正常。代码看起来像

- (void)viewDidLoad {
    [super viewDidLoad];

    GPPSignInButton *button = [[GPPSignInButton alloc] init];
    [button setStyle:kGPPSignInButtonStyleWide];
    [self.view addSubview:button];

    GPPSignIn *signIn = [GPPSignIn sharedInstance];
    signIn.shouldFetchGooglePlusUser = YES;
    signIn.shouldFetchGoogleUserEmail = YES;


    [self.signInButton setStyle:kGPPSignInButtonStyleWide];


    signIn.clientID = kClientId;
    signIn.scopes = @[@"profile"];
    signIn.delegate = self;
//    [signIn trySilentAuthentication];

}

当我运行它时,我看到了
enter image description here

所以手动添加的按钮有效,但不是我使用 xib 创建的按钮。我的 xib 看起来像
enter image description here

GooglePlusLoginViewController.h 中的代码看起来像

#import <UIKit/UIKit.h>
#import <GooglePlus/GooglePlus.h>

@class GPPSignInButton;

@interface GooglePlusLoginViewController : UIViewController <GPPSignInDelegate>
@property(weak, nonatomic) IBOutlet GPPSignInButton *signInButton;
@end

我想知道我做错了什么,有人能发现吗?

谢谢



Best Answer-推荐答案


这是一个不好的方法。如果您仔细查看输出,蓝色按钮仍保留在背景中。这是因为,您在 storyboard/xib 中添加了 UIButton,并且已将它们连接到 ViewController.h 文件。

然后您将创建 GPPSignInButton 的新实例并将其添加回您之前创建的 UIButton

您不应该在按钮内创建按钮。

顺便说一句,我今天遇到了同样的问题,这是我的解决方法。

我以编程方式创建了 GPPSignInButton,并以编程方式将其定位在 view 中。

ViewController.m

viewDidLoad 中添加这个
GPPSignInButton *button = [[GPPSignInButton alloc] init];
[button setStyle:kGPPSignInButtonStyleWide];

CGRect frame = button.frame;
frame.origin.x = 50;
frame.origin.y = 190;
button.frame = frame;

[self.view addSubview:button];

关于iOS:Google+ 按钮在 XIB 文件中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24511134/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap