I have a class that retrieves data from core data and stores it into a NSMutablearray. It also has a function that returns this array.
datamanager.h:
@interface DataManager : NSObject {
NSMutableArray *feedItems;
...
}
@property (nonatomic, retain) NSMutableArray *feedItems;
...
datamanager.m:
...
-(void)loadNews{
(load data from core data and put it in self.feedItems)
....
}
-(NSMutableArray*)getAllItems{
return self.feedItems;
}
Now i Have a UIViewController with 2 UIviews (View1 and View2) as IBOutlets. When a button in View1 is clicked it fetches the data from the datamanager class sets it as a NSMutablearray for use for a UItableviewController (tableView1).
After allocating and initializing tableView1 and setting up the Nsmutablearray to populate the table, I add its view as subview to View 2. Now my problem is when I release tableview1 after this procedure I get a EXEC_BAD_ACCESS.
View1 Button IBAction code:
-(void)loadItems{
if ([[dataManager getAllNews] count] > 0) {
ItemTableViewController *tableView1 = [[ItemTableViewController alloc] initWithNibName:@"ItemTableViewController" bundle:nil];
[tableView1 setItemList:[sectionManager getAllItems]];
for (UIView *view in View2.subviews) {
[view removeFromSuperview];
}
[View2 addSubview:tableView1.view];
[tableView1 release]; // if this is not released it works properly else EXEC_BAD_ACCESS
}
}
tableView1 setItemList function:
-(void)setItemList:(NSMutableArray *)list{
self.ItemList = list; //self.ItemList is a NSMutableArray
}
How do I properly release tableView1? Ive tried autorelease too, still doesn't work.