我有下面的代碼很奇怪的問題:當我嘗試顯示模態視圖時,爲什麼會出現CoreAnimation異常?
#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:]:無參數
這是沒有意義的。我認爲沒有理由通過一個零參數,特別是因爲沒有可能阻止我的對象被創建的特定可能原因。在過去的幾天裏,我瘋狂搜索Google,並且從來沒有見過任何有這個問題的人。如果有人有任何想法來解決這個問題,請告訴我,我沒有想法,我不知道還有什麼可以嘗試的,這是沒有意義的。
事情我至今嘗試過:
- 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'實現。 – edc1591 2011-04-29 15:49:08
我不確定,但是您不允許在viewDidLoad中顯示AlertView。嘗試在viewWillAppear或viewDidAppear中調用它。 – 2011-04-29 17:05:26
我已經添加了PasswordScreenViewController的實現。對不起,花了這麼長時間。我認爲馬塞洛可能是對的,所以我也會嘗試。 – 2011-05-01 20:17:01