更新按钮文本时程序崩溃

时间:2013-03-20 16:26:12

标签: ios objective-c

很抱歉,如果标题看起来有些含糊不清。

我正在我班级的viewDidLayoutSubviews方法中调用一个函数checkLogin。以下是该方法的代码:

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"UserLogin" accessGroup:nil];
NSString *activeUser = [keychain objectForKey:(id)kSecAttrAccount];
int length = [activeUser length];
NSLog(@"%d", length);

if (length > 0) {
    NSLog(@"Greater than 0");
    [testLabel setHidden:FALSE];
    [testLabel setText:@"Currently logged in"];
    /*

     To fix this, create a new button?

     */
    [loginButton setTitle:@"Log Out" forState:UIControlStateNormal];
} else {
    NSLog(@"Less than 0");
    [testLabel setHidden:TRUE];
    [loginButton setTitle:@"Log In" forState:UIControlStateNormal];
    //[loginButton setTitle:@"Log In" forState:UIControlStateHighlighted];
}
// Logout [keychain resetKeychainItem];

每当我尝试更改文本的标题时,我的程序崩溃了,我无法理解为什么。任何人都可以帮我解决这个问题吗?

我得到的错误是

*** Assertion failure in -[UIView layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2380.17/UIView.m:5781\ 2013-03-20 16:24:55.751 CompAir[5321:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after sending -viewDidLayoutSubviews to the view controller. FirstViewController's implementation needs to send
-layoutSubviews to the view to invoke auto layout.'}

1 个答案:

答案 0 :(得分:0)

好的,所以我现在设法解决了这个问题。由于某种原因,我对登录按钮的宽度有额外的限制,这些限制在其他按钮上没有出现(因此他们工作的原因)。删除这些约束后问题解决了。