Problems Loading a View

Discussion in 'iOS Programming' started by Lakario, Nov 10, 2008.

  1. macrumors member

    Joined:
    Oct 29, 2008
    #1
    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?
     
  2. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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.
     
  3. thread starter macrumors member

    Joined:
    Oct 29, 2008
    #3
    Thank you sir, I knew it had to be something silly like that. :)
     

Share This Page