objective-c - 为什么在尝试显示模态视图时出现 CoreAnimation 异常?

标签 objective-c cocoa-touch ios core-animation

我在使用以下代码时遇到了一个非常奇怪的问题:

#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 Methods pragma mark”。

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

CoreAnimation: ignoring exception: * -[NSPlaceholderString initWithString:]: nil argument

这毫无意义。我认为它没有理由传递一个 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

最佳答案

newPassword = [NSString stringWithString:nil];
repeatNewPassword = [NSString stringWithString:nil];

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

关于objective-c - 为什么在尝试显示模态视图时出现 CoreAnimation 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5834230/

相关文章:

ios - future 相对日期人类可读形式

cocoa-touch - 当键不存在时,NSMutableDictionary 返回 0xffffffff 而不是 nil

iphone - 为小型固定大小的 UITableView 禁用单元格重用

ios - 使用 presentViewController 呈现 View :animated:completion: not working when presentViewController:animated:completion: hotspot enabled

xcode - 更改日历隐私时,iOS 7应用程序崩溃

ios - 如何在 iOS 中使用幻灯片删除 SubView?

ios - 此应用目前无法使用 Facebook 登录

ios - 调用 Super.init(编码器 : aDecoder)) 时应用程序突然崩溃

iphone - 在 iOS 设备上启动应用程序时出现 XCode 4.4 错误

objective-c - 稳定的类似恒温器的算法,其中输入变化可能很大且突然