tags:

views:

72

answers:

2

My application is crashing, I think, in RootController.m and I don't know why. It occurs when I am in any view controller and I push the back button. It briefly returns to RootController and then it crashes. There is no messages on the console. I don't think it is the ViewController as I have tried more than one.

Here is the code.

#import "RootViewController.h"


@implementation RootViewController

@synthesize menuData;


- (void)viewDidLoad {

    NSArray *array = [[NSArray alloc] initWithObjects: @"Sales", @"Refunds",   @"Auth",     nil];

self.menuData = array;

[array release];

    [super viewDidLoad];

self.title = @"Main Menu";

}

  • (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 anything that can be recreated in viewDidLoad or on demand. // e.g. self.myOutlet = nil;

    self.menuData = nil;

    [super viewDidUnload]; }

    • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }

    // Customize the number of rows in the table view.

    • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

      return [self.menuData count]; }

    // Customize the appearance of table view cells.

    • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath {

      static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }

      // Configure the cell. NSInteger row = [indexPath row]; cell.text = [menuData objectAtIndex:row]; return cell; }

    // Override to support row selection in the table view.

    • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

      // Navigation logic may go here -- for example, create and push another view controller. //salesViewController *anotherViewController = [[salesViewController alloc] initWithNibName:@"salesView" bundle:nil]; confirmViewController *anotherViewController = [[confirmViewController alloc] initWithNibName:@"confirmView" bundle:nil];

      [self.navigationController pushViewController:anotherViewController animated:YES]; [anotherViewController release];

      }

    • (void)dealloc {

      [menuData release]; [super dealloc]; }

@end

+1  A: 

You are most likely releasing something twice in your SalesViewController, it's crashing when that object's dealloc is getting called and doing the 2nd release.

You didn't include that contorller's code, either look for it yourself or paste it here and I'll help you spot it :)

Here's a scenario you should look for:

// 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
}

EDIT after your target view controller was pasted:

It might be because you forgot to set one of the properties you're releasing in the dealloc. Try setting a breakpoints in your dealloc and see if one of the properties is actually null before releasing it, if so, that's why it crashes.

EDIT #2, are you sure you want to be calling [lblSometing dealloc] instead of [lblSomething release]?

Prody
It happens with another view controller as well. That one is a little shorter so I will paste in below. Any help appreciated.
jp chance
A: 

#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

jp chance
please edit this and re-format it. When pasting code, don't manually indent, just paste all your code, then select it all and click the "Code" icon in the site's editor's toolbar, it will format your code properly. I can't read it :(
Prody
BTW, see my EDIT in my answer
Prody