PDA

View Full Version : Problems Loading a View




Lakario
Nov 10, 2008, 11:24 AM
I have a view defined in the interface builder that contains a subview that will be used to contain a custom tableview. The tableview is loaded into the subview in the viewDidLoad event of the view that contains it, and then upon being loaded does a bit of work on a provided list of items and populates the table accordingly.

Trouble is, when I load the tableView and attempt to perform any operations on it, I get a EXC_BAD_ACCESS error from the debugger:

PriceHistoryViewController.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface PriceHistoryViewController : UITableViewController {
NSMutableArray *priceList;
}

@property (nonatomic, retain) NSMutableArray *priceList;

- (void)sortAndColorPriceHistory;

- (void)setPriceList:(NSMutableArray *)priceArray;

- (void)doSomething;

@end


SellViewController.m - viewDidLoad()

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

if(priceHistoryTable == nil) {
PriceHistoryViewController *controller = [[PriceHistoryViewController alloc] initWithNibName:@"PriceHistoryView" bundle:[NSBundle mainBundle]];
priceHistoryTable = controller;
[controller release];
}

//....unrelated stuff

[priceHistoryTable doSomething];
[priceTableView addSubview:priceHistoryTable.view];
}


Any message I send to priceHistoryTable produces an EXC_BAD_ACCESS error, but there's no apparent indication of the problem. According to my debugging the priceHistoryTable is being created successfully and it is not nil before I perform operations on it.

The doSomething method I call above is only supposed to put a message in the NSLog, but even that causes a problem. Ideas?



PhoneyDeveloper
Nov 10, 2008, 12:07 PM
The problem is that you're not retaining the priceHistoryTable view controller. You don't show much of the SellViewController code. If you have a property for priceHistoryTable then you should use it when you assign the priceHistoryTable variable.

self. priceHistoryTable = controller;

Since you're not retaining the view controller it's being released before you use it.

Lakario
Nov 10, 2008, 01:45 PM
The problem is that you're not retaining the priceHistoryTable view controller. You don't show much of the SellViewController code. If you have a property for priceHistoryTable then you should use it when you assign the priceHistoryTable variable.

self. priceHistoryTable = controller;

Since you're not retaining the view controller it's being released before you use it.

Thank you sir, I knew it had to be something silly like that. :)