0

对不起,如果标题似乎有点模棱两可。

我正在从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.'}
4

1 回答 1

0

好的,所以我现在设法解决了这个问题。出于某种原因,我对我的登录按钮的宽度有额外的限制,这些限制在其他按钮上不存在(以及它们为什么起作用)。消除这些约束后问题解决。

于 2013-03-20T16:56:35.557 回答