返回RootController会崩溃我的应用程序

时间:2009-11-05 17:05:28

标签: iphone

我认为我的应用程序在RootController.m崩溃,我不知道为什么。它出现在我在任何视图控制器中,我按下后退按钮。它会暂时返回RootController,然后崩溃。控制台上没有消息。我不认为这是ViewController,因为我尝试了不止一次。

这是代码。

    #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

1 个答案:

答案 0 :(得分:1)

你最有可能在SalesViewController中发布两次,当该对象的dealloc被调用并进行第二次释放时崩溃。

您没有包含该控制器的代码,您可以自己查找或将其粘贴到此处,我会帮助您发现它:)

以下是您应该寻找的方案:

// 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中设置一个断点,看看其中一个属性在释放之前是否实际为null,如果是,那就是它崩溃的原因。

编辑#2,您确定要拨打[lblSometing dealloc]而不是[lblSomething release]吗?