Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lakario

macrumors member
Original poster
Oct 29, 2008
30
0
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
Code:
#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()
Code:
// 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

macrumors 68040
Sep 2, 2008
3,114
93
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.

Code:
self. priceHistoryTable = controller;

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

Lakario

macrumors member
Original poster
Oct 29, 2008
30
0
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.

Code:
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. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.