Gold Challenge Issue - Unbalanced calls


#1

I’m hoping there is an easy solution to this but I’ve been trying to fix it for hours and think I’m just missing something. I have everything working for the Gold Challenge, but for some reason, I have to hit the back button twice to get back to the DetailControllerView after I change the date created. The first time, the button says “Back”, then the second time it says “Rusty Spork”. Also, as soon as I click on the button to move to the DateChange view, I receive these messages in the log:

[quote]2013-05-17 17:08:08.266 Homepwnr[6858:c07] nested push animation can result in corrupted navigation bar
2013-05-17 17:08:08.624 Homepwnr[6858:c07] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2013-05-17 17:08:08.626 Homepwnr[6858:c07] Unbalanced calls to begin/end appearance transitions for <DateViewController: 0x751d480>.[/quote]

Now everything works, the date changes, is stored, and I eventually get back to the Detailed View, it just takes two button presses. Any idea what gives? Code is below.

Thanks for the great book, and helpful forum users!

DetailedViewController.m:

#import "DetailViewController.h"
#import "BNRItem.h"
#import "DateViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController
@synthesize item;

-(void)viewDidLoad
{
    [super viewDidLoad];
    [[self view] setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
}

-(void)setItem:(BNRItem *)i
{
    item = i;
    [[self navigationItem] setTitle:[item itemName]];

}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear];
    [nameField setText:[item itemName]];
    [serialNumberField setText:[item serialNumber]];
    [valueField setText:[NSString stringWithFormat:@"%d", [item valueInDollars]]];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
    
    [dateLabel setText:[dateFormatter stringFromDate:[item dateCreated]]];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear];
    
    [[self view] endEditing:YES];
    
    [item setItemName:[nameField text]];
    [item setSerialNumber:[serialNumberField text]];
    [item setValueInDollars:[[valueField text] intValue]];
}
//Silver Challenge
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [[self view] endEditing:YES];
   
}
//Make hitting return close the keyboard
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
//Move to DateView
-(IBAction)changeTheDate:(id)sender
{
    DateViewController *dateViewController = [[DateViewController alloc] init];
    
    //Pass the item to date view controller
    [dateViewController setItem:item];
    
    [[self navigationController] pushViewController:dateViewController animated:YES];
}

@end

DateViewController.h

#import "DateViewController.h"
#import "BNRItem.h"

@interface DateViewController ()

@end
@implementation DateViewController

@synthesize item;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [[self view] setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
    [itemDate setDate:[item dateCreated]];
}
- (void) setItem:(BNRItem *)i
{
    item = i;
}

-(void)viewWillDisappear:(BOOL)animated
{
    [item setDateCreated:[itemDate date]];
    
    [super viewWillDisappear];
    [[self view] endEditing:YES];

}

@end