我在使用以下代码时遇到了一个非常奇怪的问题:
#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:忽略异常: * - [NSPlaceholderString initWithString:]:nil参数
这没有任何意义。我认为没有理由传递一个nil参数,特别是因为没有特别可能的原因会阻止我的对象被创建。我在最近几天用Google搜索过疯狂,我从来没有见过有这个特殊问题的人。如果有人有任何想法来解决它,请让我知道,我没有想法,我不知道我还能尝试什么,这没有任何意义。
到目前为止我尝试过的事情:
编辑:
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
答案 0 :(得分:1)
newPassword = [NSString stringWithString:nil];
repeatNewPassword = [NSString stringWithString:nil];
这就是你要找的东西。尝试使用newPassword = nil
或newPassword = @""
初始化。
答案 1 :(得分:1)
我知道这已经得到了解答,但我想说的是我也有这样的问题:
CoreAnimation:忽略异常
还有一个在UIAlertViewDelegate方法中采取的动作的原点。
这有点棘手,因为我认为错误与UI中的某些动画内容有关,但错误与此无关,只是在我的代码中,就像在这个问题中一样。
因此,如果您看到此错误,则表示该应用程序应该已崩溃并终止但由于某种原因它未终止(这使得跟踪更加困难......)。忘记CoreAnimation并开始调试! :P