Search code examples
objective-ccocoa-touchioscore-animation

Why Am I Getting a CoreAnimation Exception When I Try To Show A Modal View?


I am having a very weird problem with the following code:

#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

Go to my "UIAlertViewDelegate Methods pragma mark.

For some reason, I get the following message in the console whenever I try to show the modal view:

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

Which makes no sense. I see no reason for it to pass a nil argument, specially since there is no particular possible cause that could prevent my object from being created. I have Googled like crazy in the last few days and I have NEVER seen anyone with this particular problem. If someone has any idea to fix it, please let me know, I am out of ideas, I don't know what else I could try, and it makes no sense.

Things I have tried so far:

  • loadWithNibName:
  • Try to show my modal view without calling an AlertView at all.

EDIT:

PasswordScreenView Implementation:

    //
//  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

Solution

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

    This is what you're looking for. Try initializing with newPassword = nil or newPassword = @"".