2009-11-05 24 views
0

我的應用程序崩潰,我想,在RootController.m,我不知道爲什麼。它出現在我在任何視圖控制器中時,我按下後退按鈕。它暫時返回到RootController然後它崩潰。控制檯上沒有消息。我不認爲這是ViewController,因爲我嘗試了多個。返回到RootController崩潰我的應用程序

這是代碼。

#import "confirmViewController.h" 


    @implementation confirmViewController 

    @synthesize lblStatus; 
    @synthesize lblCardType; 
    @synthesize lblCardNumber; 
    @synthesize lblExpires; 
    @synthesize lblAmount; 
    @synthesize lblApproval; 

    @synthesize strConfirmation; 
    @synthesize strCardNumber; 
    @synthesize strExpires; 
    @synthesize strAmount; 
    @synthesize strApproval; 

/* 
// 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 { 
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
     // Custom initialization 
    } 
    return self; 
} 
*/ 


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    //prepare confirmation, all that is needed is the first string  
    NSArray *strings = [strConfirmation componentsSeparatedByString: @","]; 
    NSString *strPreParsed = [strings objectAtIndex:0]; 

    //break out yes/no so we can set status 
    //NSString *strYesNO = [strPreParsed substringToIndex:2]; 
    NSString *strYesOrNo = [strPreParsed substringWithRange: NSMakeRange(1, 1)]; 

    //save approval for later 
    strApproval = strYesOrNo; 

    //debug 
     NSLog(@"strNo= %@",strYesOrNo); 
     NSLog(@"strPreParsed= %@", strPreParsed); 


    if([strYesOrNo compare:@"Y"] == NSOrderedSame) 
    { 
     lblStatus.text = @"Approved"; 
     lblStatus.textColor = [UIColor greenColor]; 
    } 

    if([strYesOrNo compare:@"N"] == NSOrderedSame) 
    { 
     lblStatus.text = @"Declined"; 
     lblStatus.textColor = [UIColor redColor]; 
    } 

    if([strYesOrNo compare:@"U"] == NSOrderedSame) 
    { 
     lblStatus.text = @"Try Again"; 
     lblStatus.textColor = [UIColor redColor]; 
    } 

    //set card type 
    if([lblCardNumber.text compare:@"4"] == NSOrderedSame) 
    { 
     lblCardType.text = @"Visa"; 
    } 

    if([lblCardNumber.text compare:@"5"] == NSOrderedSame) 
    { 
     lblCardType.text = @"Master"; 
    } 

    if([lblCardNumber.text compare:@"6"] == NSOrderedSame) 
    { 
     lblCardType.text = @"Discover"; 
    } 



    //set cardnumber 
    lblCardNumber.text = strCardNumber; 

    //set expires 
    lblExpires.text = strExpires; 

    //set amount 
    lblAmount.text = strAmount; 

    //set approval string 
    lblApproval.text = strPreParsed; 


} 


/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 

- (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 { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 

    //show signature 
    sigCaptureViewController *yetAnotherViewController = [[sigCaptureViewController alloc] initWithNibName:@"sigCaptureView" bundle:nil]; 
    [self.navigationController pushViewController:yetAnotherViewController animated:YES]; 
    [yetAnotherViewController release]; 

} 


- (void)dealloc { 
    [super dealloc]; 

    [lblCardType dealloc]; 
    [lblCardNumber dealloc]; 
    [lblExpires dealloc]; 
    [lblAmount dealloc]; 
    [lblApproval dealloc]; 
    [lblStatus dealloc]; 

    [strConfirmation dealloc]; 
    [strCardNumber dealloc]; 
    [strExpires dealloc]; 
    [strAmount dealloc]; 
    [strApproval dealloc]; 
} 


@end 
+0

你有一個堆棧跟蹤? – bradheintz 2009-11-05 17:11:48

回答

1

你最有可能在你的SalesViewController釋放兩次的東西,它的崩潰時對象的dealloc中獲取調用,做第二個版本。

你不包括contorller的代碼,要麼尋找它自己或它粘貼在這裏,我會幫你發現它:)

這裏有一個情況下,你應該尋找:

// somewhere within your sales controller 
- (void)someWhere { 
    NSArray *arr = [NSArray array]; 
    self.myArray = arr; 
    [arr release]; // notice how arr wasn't initialized with an init 
    // so no release is required 
    // but since your myArray is a @property(retain) it won't crash here 
    // because the property did a retain 
} 

- (void)dealloc { 
    [myArray relase]; // this does the 2nd release and BOOM 
} 

粘貼目標視圖控制器後編輯:

這可能是因爲您忘記在dealloc中設置其中一個屬性。嘗試在你的dealloc中設置一個斷點,看看其中一個屬性在釋放之前是否真的爲空,如果是這樣,那就是它崩潰的原因。

編輯#2,您確定要撥打[lblSometing dealloc]而不是[lblSomething release]嗎?

+0

它也發生在另一個視圖控制器上。那個稍​​微短一點,所以我會在下面粘貼。任何幫助讚賞。 – 2009-11-05 17:15:35