当我尝试显示模态视图时,为啥会出现 CoreAnimation 异常?

Posted

技术标签:

【中文标题】当我尝试显示模态视图时,为啥会出现 CoreAnimation 异常?【英文标题】:Why Am I Getting a CoreAnimation Exception When I Try To Show A Modal View?当我尝试显示模态视图时,为什么会出现 CoreAnimation 异常? 【发布时间】:2011-04-29 15:46:18 【问题描述】:

以下代码有一个非常奇怪的问题:

#import "MainApplicationViewController.h"
#import "PasswordScreenViewController.h"

@implementation MainApplicationViewController

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
        // Custom initialization.
    
    return self;

*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
    [super viewDidLoad];
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"appHasBeenLaunchedBefore"] == NO)
        UIAlertView *firstLaunch = [[UIAlertView alloc] initWithTitle:@"Set Password." message:@"This is the first time you launch the app. Would you like to set a password now?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        [firstLaunch show];
        [firstLaunch release];
    


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

*/

#pragma mark -
#pragma mark UIAlertViewDelegate Methods

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
    //No = 0. Yes = 1.
    if(buttonIndex == 1) 
        PasswordScreenViewController *psvc = [[PasswordScreenViewController alloc] init];
        [self presentModalViewController:psvc animated:NO];
    


#pragma mark -
#pragma mark Memory Management

- (void)didReceiveMemoryWarning 
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.


- (void)viewDidUnload 
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;



- (void)dealloc 
    [super dealloc];



@end

转到我的“UIAlertViewDelegate 方法杂注标记。

由于某种原因,每当我尝试显示模态视图时,我都会在控制台中收到以下消息:

CoreAnimation:忽略异常:* -[NSPlaceholderString initWithString:]: 无参数

这没有任何意义。我认为它没有理由传递 nil 参数,特别是因为没有特别的可能原因可以阻止我的对象被创建。在过去的几天里,我疯狂地用谷歌搜索,我从未见过有人遇到这个特殊问题。如果有人有任何解决它的想法,请告诉我,我没有想法,我不知道我还能尝试什么,这没有任何意义。

到目前为止我尝试过的事情:

loadWithNibName: 尝试在不调用 AlertView 的情况下显示我的模态视图。

编辑:

PasswordScreenView 实现:

    //
//  PasswordScreenViewController.m
//
//  Created by  on 4/23/11.
//  Copyright 2011 . All rights reserved.
//

#import "PasswordScreenViewController.h"
#import <Security/Security.h>
#import "SFHFKeychainUtils.h"

@implementation PasswordScreenViewController
@synthesize p1, p2, p3, p4;
@synthesize vp1, vp2, vp3, vp4;
@synthesize delegate;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad

    [super viewDidLoad];
    p1.text = @" ";
    p2.text = @" ";
    p3.text = @" ";
    p4.text = @" ";
    vp1.text = nil;
    vp2.text = nil;
    vp3.text = nil;
    vp4.text = nil;
    NSError *error;
    currentPassword = [NSString stringWithString:[SFHFKeychainUtils getPasswordForUsername:@"user" andServiceName:@"com.atanacross.myprincesses.password" error:&error]];
    newPassword = [NSString stringWithString:nil];
    repeatNewPassword = [NSString stringWithString:nil];
    [p1 becomeFirstResponder];


-(id)initWithMode:(NSString *)mode

    self = [super init];
    return self;


#pragma mark -
#pragma mark UITextFieldDelegate Methods

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

    if(range.length != 1)
    
        if(textField == p1)
        
            p1.text = string;
            vp1.text = string;
            [p2 becomeFirstResponder];
        else if(textField == p2)
        
            p2.text = string;
            vp2.text = string;
            [p3 becomeFirstResponder];
        else if(textField == p3)
        
            p3.text = string;
            vp3.text = string;
            [p4 becomeFirstResponder];
        else if(textField == p4)
        
            p4.text = string;
            vp4.text = string;
        
    else
    
        if(textField == p4)
        
            p4.text = @" ";
            vp4.text = nil;
            [p3 becomeFirstResponder];
        else if(textField == p3)
        
            p3.text = @" ";
            vp3.text = nil;
            [p2 becomeFirstResponder];
        else if(textField == p2)
        
            p2.text = @" ";
            vp2.text = nil;
            [p1 becomeFirstResponder];
        else if(textField == p1)
        
            p1.text = @" ";
            vp1.text = nil;
        
    
    return NO;


-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField

    if(textField == vp1 || textField == vp2 || textField == vp3 || textField == vp4)
    
        return NO;
    
    return YES;


#pragma mark -
#pragma mark Memory Management

- (void)didReceiveMemoryWarning

    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.


- (void)viewDidUnload

    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.p1 = nil;
    self.p2 = nil;
    self.p3 = nil;
    self.p4 = nil;
    self.vp1 = nil;
    self.vp2 = nil;
    self.vp3 = nil;
    self.vp4 = nil;



- (void)dealloc

    [p1 release];
    [p2 release];
    [p3 release];
    [p4 release];
    [vp1 release];
    [vp2 release];
    [vp3 release];
    [vp4 release];
    [super dealloc];



@end

【问题讨论】:

我想我们需要看看你的PasswordScreenViewController 实现。 我不确定,但不允许在 viewDidLoad 中显示 AlertView。尝试在 viewWillAppear 或 viewDidAppear 中调用它。 我已经添加了 PasswordScreenViewController 的实现。抱歉花了这么长时间。我认为马塞洛可能是对的,所以我也会尝试。 【参考方案1】:
newPassword = [NSString stringWithString:nil];
repeatNewPassword = [NSString stringWithString:nil];

这就是你要找的。尝试使用newPassword = nilnewPassword = @"" 进行初始化。

【讨论】:

我不知道如何解决我的问题?无论如何我都试过了,但我仍然收到相同的错误消息。 哦,没关系!你真是个天才哈哈。为什么会停止?两个推荐的字符串并没有解决我的问题。它实际上是 currentPassword。我按照您在当前密码中所说的进行了测试,这有点道理,因为当没有密码时,currentPassword 为零。非常感谢您的解决方案,考虑到我几天前在许多其他地方问过并且没有人能够回答它,无法相信您得到它的速度有多快。非常感谢,我真的很感激。【参考方案2】:

我知道这个问题已经得到解答,但我想指出我也遇到过这样的问题:

CoreAnimation:忽略异常

还具有在 UIAlertViewDelegate 方法内执行的操作的来源。

这有点棘手,因为我认为该错误与 UI 中的某些动画内容或某些内容有关,但该错误与此无关,只是我的代码中的某些内容,就像在这个问题中一样。

因此,如果您看到此错误,则意味着应用程序应该已经崩溃并终止,但由于某种原因它没有终止(这使得追踪变得更加困难......)。忘记 CoreAnimation 并开始调试吧! :p

【讨论】:

以上是关于当我尝试显示模态视图时,为啥会出现 CoreAnimation 异常?的主要内容,如果未能解决你的问题,请参考以下文章

当我尝试快速加载我的表格视图时,为啥会出现 EXC_BAD_INSTRUCTION 错误?

为啥一个简单的模态视图控制器在呈现和关闭时会滞后?

为啥模态演示表单未按预期显示?

使用 SwiftUI,我们在 List 中安装了一个 Button。为啥当我点击按钮显示模态然后再次关闭时模态消失?

当我将滚动方向从垂直更改为水平时,为啥集合视图会崩溃?

使用与模态视图冲突的实体卡