我曾在一个应用程序上工作过。我以编程方式添加了表视图。这个应用程序在低于4.2的任何xcode中正常工作,但当我尝试在xcode 4.2发布版本上运行它时,它会在表视图重新加载时出现问题。如何修复错误。请给我一些解决方案来解决xcode 4.2中的错误。
-(void)viewDidAppear:(BOOL)animated{
DebugLog(@"start");
[self.tableView reloadData];
execountarray=[[NSMutableArray alloc]init];
for(int k=0;k<[mSubUnitsArray count];k++)
{
SubUnit *subUnit = (SubUnit*)[mSubUnitsArray objectAtIndex:k];
NSArray *subUnitExercises = [subUnit.subUnitExercise allObjects];
[execountarray addObject:[NSString stringWithFormat:@"%d",[subUnitExercises count]]];
}
///////////////
if (managedObjectContext){
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"TSubUnitExerciseProgress" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
// Order the events by creation date, most recent first.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"editDate" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];
// Execute the fetch -- create a mutable copy of the result.
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error.
myNotes = nil;
[myNotes removeAllObjects];
}
else
{
[myNotes setArray: mutableFetchResults];
}
//NSLog(@"My notes count:--------unitviewcontroller--------------->%d",[myNotes count]);
if([myNotes count] ==0)
{
setExer1Done:NO;
setExer2Done:NO;
}
else
{
NSLog(@"hey :P");
}
}
[self.tableView reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//DebugLog(@"-start- \n");
CGFloat height = 0.0;
SubUnit *subUnit = (SubUnit*)[mSubUnitsArray objectAtIndex:indexPath.row];
NSArray *subUnitExercises = [self sortArray:[subUnit.subUnitExercise allObjects]];
NSLog(@"mSelectedSubUnitIndex:%d",mSelectedSubUnitIndex.row);
NSLog(@"subUnitExercises:%d",[subUnitExercises count]);
if (indexPath.row==mSelectedSubUnitIndex.row && [subUnitExercises count]>1) {
height =CELL_EXPAND_HEIGHT ;
}
else {
height = CELL_NORMAL_HEIGHT;
}
return height;
}
它在NSLog崩溃(@“mSelectedSubUnitIndex:%d”,mSelectedSubUnitIndex.row);可能是它没有加载索引路径。这里mSelectedSubUnitIndex是索引路径。 非常感谢。