I am trying to release the label text each time the person click on a book title from the table view, it should change the detailViewController label (titleLabel) however it keeps showing the same book title.
Wondering If i have done something wrong – well I know I have but wondering how I fix it…
//
// BookDetailViewController.m
#import "BookDetailViewController.h"
#import "Book.h"
@implementation BookDetailViewController
@synthesize aBook, titleLabel;
// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
[super viewDidLoad];
[self bookDes];
self.title = @"Book Detail";
}
-(void)bookDes {
[self.titleLabel setText:nil];
[self.titleLabel setText:aBook.title];
}
- (void)dealloc {
[aBook release];
[titleLabel release];
[super dealloc];
}
@end
You are calling [self bookDes] from viewDidLoad… This method is called after a view controller has loaded its associated views into memory. How are you creating the BookDetailViewController? If you only create it once and then reuse the controller each time a user presses a book title, the viewDidLoad method will also only be called once.
If you already have the book title in your parent controller, why don’t you just set the property from there when you push the child onto the navigation controller?
EDIT FROM COMMENT:
Yes, the BookDetailsViewController is created once, then saved… so the viewDidLoad is only called once.
One thing you could try is setting the label in the parent’s didSelectRowAtIndexPath method:
there are better ways to do this like overriding the setter on the details controller and setting the label… but you should keep it simple and get it working first.
Hope this helps