I'm developing a simple navigation-based iPad app. The initial screen shows a TableView with sort buttons in the toolbar at the bottom.
Everything works fine until I try to change the sort order (via the sort buttons) on the fetchRequest and try to reloadData on the tableVIew.
I'm receiving a "EXC_BAD_ACCESS" error message.
Here is the code being called by the sort buttons:
The first time the routine is called is crashes on the last line:
When I comment out this call to reloadData and try running this code, the code will execute fine the first time (although not refreshing the data), but the second time I call this routine (via the same sort button), it crashes on the setSortDescriptors line:
Yes...I'm still fairly new to iOS and iPad development, but learning quickly. So, any help would be greatly appreciated.
Thanks, T.D.
Everything works fine until I try to change the sort order (via the sort buttons) on the fetchRequest and try to reloadData on the tableVIew.
I'm receiving a "EXC_BAD_ACCESS" error message.
Here is the code being called by the sort buttons:
Code:
-(IBAction) toolbarSortOrderChanged: (id)sender
{
NSLog(@"toolbarSortOrderChanged");
// Get the fetch request from the controller and change the sort descriptor
NSFetchRequest* fetchRequest = self.fetchedResultsController.fetchRequest;
// Edit the sort key based on which button was pressed
BOOL ascendingOrder = NO;
UIBarButtonItem* button = (UIBarButtonItem*) sender;
if ([button.title compare:@"Ascending"]== NSOrderedSame)
ascendingOrder=YES;
else
ascendingOrder=NO;
NSSortDescriptor *sortDescriptor =
[[NSSortDescriptor alloc] initWithKey:@"periodStartDate" ascending:ascendingOrder];
NSArray *sortDescriptors =
[[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
[error release];
[fetchRequest release];
[self.timesheetTableView reloadData];
}
The first time the routine is called is crashes on the last line:
Code:
[self.timesheetTableView reloadData];
When I comment out this call to reloadData and try running this code, the code will execute fine the first time (although not refreshing the data), but the second time I call this routine (via the same sort button), it crashes on the setSortDescriptors line:
Code:
[fetchRequest setSortDescriptors:sortDescriptors];
Yes...I'm still fairly new to iOS and iPad development, but learning quickly. So, any help would be greatly appreciated.
Thanks, T.D.