So, I have a UIViewTable and a UISearchBar with two zoom buttons. The idea is that when I click the area button, the data source for the UIViewTable changes, but I get an EXC_BAD_ACCESS error.
I have the following code in the UIViewController SearchViewController.m:
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange: (NSInteger) selected scope
{
MyAppDelegate *delegate = (MyAppDelegate *) [[UIApplicationsharedApplication] delegate];
if (self.listData != nil) {
[self.listData release];
}
if (selectedScope == 0) {
self.listData = [delegate.data getListOne];
}
else {
self.listData = [delegate.data getListTwo];
}
}
- (void) viewDidLoad {
MyAppDelegate *delegate = (MyAppDelegate*) [[UIApplication sharedApplication] delegate];
self.listData = [delegate.data getListOne];
}
in my SearchViewController.h I have:
@property (nonatomic,retain) NSMutableArray *listData;
in my data. I have:
-(NSMutableArray *) getListOne {
NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:@"test1",
@"test2",
nil];
[list autorelease];
return list;
}
-(NSMutableArray *) getListTwo {
NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:@"test3",
@"test4",
nil];
[list autorelease];
return list;
}
Failure:
self.listData = [delegate.data getListTwo];
I checked it when I set the property with which it falls. I understand that when I create a new NSMutableArray in Data.m, I assign it auto-advertisement, as it should.
When the view loads, I assign it to my listData, and as I access the saved property, the reference count is incremented (so there are now 2 auto-pending it).
, , , listData ( ), , NSMutableArray 0 ( , ).
NSMutableArray ... ? : (
oh NSMutableArray, tableView - , if, , ?? / , , :)