首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode 6按钮目标不工作

Xcode 6按钮目标不工作
EN

Stack Overflow用户
提问于 2014-09-18 06:32:38
回答 2查看 2.3K关注 0票数 2

我只是安装了Xcode6来测试我的应用程序如何使用它。

初始页面上的facebook登录按钮似乎不起作用。

下面是我的代码:

代码语言:javascript
复制
@property (nonatomic, strong) UIButton *loginButton;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.loginButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 70)];
    self.loginButton.center = self.view.center;
    [self.loginButton setImage:[UIImage imageNamed:@"login_fb.png"] forState:UIControlStateNormal];

    [self.view addSubview:self.loginButton];
    [self.loginButton addTarget:self action:@selector(loginButtonPressed) forControlEvents:UIControlEventTouchUpInside];
 }

-(void)loginButtonPressed
{
      // perform login
}

重要的是要注意,应用程序在不同的视图上启动。在视图控制器中,我检查用户是否存在,如果不存在,则显示登录视图。以下是代码:

代码语言:javascript
复制
 if ([DCTUserIdentity currentIdentity] == nil) {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
    DCTInitialLoginVC *vc = [sb instantiateViewControllerWithIdentifier:@"InitialLogin"];
    vc.delegate = self;
    [self presentViewController:vc animated:NO completion:^{}];
}

我在loginButtonPressed函数中设置了一个断点,但当我尝试单击button....any时,它永远不会被击中。这是怎么回事?

EN

回答 2

Stack Overflow用户

发布于 2014-09-24 10:09:05

看起来这实际上不是一个bug,而是一个使用Xcode6定位iOS 7设备的不兼容问题。ecotax's post对此进行了更详细的描述,但这里是来自Apple DTS的回应:

在iOS 7中,单元格的内容视图通过自动调整蒙版大小来调整大小。在iOS 8中,这一点发生了变化,单元格停止使用自动调整蒙版大小,并开始在layoutSubviews中调整内容视图的大小。如果nib在iOS 8中编码,然后在iOS 7上解码,您将拥有一个没有自动调整大小掩码的内容视图,并且没有其他方法来调整自身的大小。因此,如果您更改了单元格的框架,内容视图将不会跟随。

要部署回iOS 7的应用程序将不得不通过调整内容视图本身的大小、添加自动调整大小的掩码或添加约束来解决此问题。

解决方法:

代码语言:javascript
复制
- (void)awakeFromNib
{
   // Fix for iOS 7 devices targeted using Xcode 6.
   self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
票数 0
EN

Stack Overflow用户

发布于 2014-10-10 22:28:02

尝试以下代码:

代码语言:javascript
复制
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginButton.frame = CGRectMake(0, 0, 200, 70);
    self.loginButton.center = self.view.center;
    [self.loginButton setImage:[UIImage imageNamed:@"login_fb.png"]
                      forState:UIControlStateNormal];

    [self.view addSubview:self.loginButton];
    [self.loginButton addTarget:self action:@selector(loginButtonPressed:)     
               forControlEvents:UIControlEventTouchUpInside];

}

并使用强指针持有DCTInitialLoginVC对象。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25901394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档