2011-04-29 87 views
1

我有下面的代碼很奇怪的問題:當我嘗試顯示模態視圖時,爲什麼會出現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 
+1

我想我們需要看看你的'PasswordScreenViewController'實現。 – edc1591 2011-04-29 15:49:08

+1

我不確定,但是您不允許在viewDidLoad中顯示AlertView。嘗試在viewWillAppear或viewDidAppear中調用它。 – 2011-04-29 17:05:26

+0

我已經添加了PasswordScreenViewController的實現。對不起,花了這麼長時間。我認爲馬塞洛可能是對的,所以我也會嘗試。 – 2011-05-01 20:17:01

回答

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

這是你在找什麼。嘗試使用newPassword = nilnewPassword = @""進行初始化。

+0

我不知道如何解決我的問題,但?無論如何,我嘗試過,但我仍然收到相同的錯誤信息。 – 2011-05-01 20:24:06

+0

哦,別介意!你是個天才哈哈。爲什麼這會停止?兩個建議的字符串並沒有解決我的問題。它實際上是currentPassword。我做了你在當前密碼中所說的測試,它有道理,因爲當沒有密碼時,currentPassword將變爲零。感謝你的解決方案,不能相信你有多快,考慮到我在很多其他地方問過幾天,沒有人能夠回答它。非常感謝,我非常感謝。 – 2011-05-01 20:26:30

+0

不客氣:) – cweinberger 2011-05-01 20:33:16

1

我知道這是回答,但想此話,我也有過這樣的問題:

CoreAnimation:忽略異常

原產於UIAlertViewDelegate方法中採取的行動

也。

這有點棘手,因爲我認爲錯誤與UI中的某些動畫或東西有關,但錯誤與此無關,只是我的代碼中的一些東西,就像在這個問題中一樣。

所以,如果你看到這個錯誤,這意味着該應用程序應該崩潰並終止,但由於某種原因它不會終止(這使得更難追蹤...)。忘記CoreAnimation並開始調試! :p

+0

節省我的時間。謝謝 – Michael 2012-01-11 00:20:50

相關問題