Reputation: 5742
I am trying to draw the number of rows according to which section they are in. Code:
-(void)configureView:(NSDictionary *)serverResult{
NSManagedObject * detailData = [serverResult valueForKey:@"details"];
NSSet * projID = [detailData valueForKey:@"PROJECTID"];
NSSet * projStat = [detailData valueForKey:@"PROJECTSTATUS"];
NSSet * appDate = [detailData valueForKey:@"BOARDAPPROVALDATE"];
NSSet * closeDate = [detailData valueForKey:@"LOANCLOSINGDATE"];
NSSet * countryName = [detailData valueForKey:@"COUNTRYNAME"];
NSSet * regionName = [detailData valueForKey:@"REGIONNAME"];
NSSet * envCatCode = [detailData valueForKey:@"ENVASSESMENTCATEGORYCODE"];
NSSet * teamLeader = [detailData valueForKey:@"TEAMMEMFULLNAME"];
NSSet * borrower = [detailData valueForKey:@"BORROWER"];
NSSet * impAgency = [detailData valueForKey:@"IMPAGENCY"];
NSSet * totalCost = [detailData valueForKey:@"LENDINGPROJECTCOST"];
NSSet * comtAmt = [detailData valueForKey:@"IBRDPLUSIDAAMT"];
basic = [NSArray arrayWithObjects:projID, projStat, appDate, closeDate,countryName,regionName,envCatCode,teamLeader,borrower,impAgency,totalCost,comtAmt, nil];
}
- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section
{
int number;
switch (section) {
case 0:
number = basic.count;
break;
case 1:
number = allSectors.count;
break;
case 2:
number = 1;
break;
default:
break;
}
return number;
}
But code crashes with EXC_BAD_Access Please help!!!
Upvotes: 0
Views: 199
Reputation: 38728
It normally means you are trying to access a variable that has been released already. Judging by the way you are accesing the ivars directly (not through getters) it suggests that you are doing all the memory management yourself which can be tricky to always get right.
In this line where you set the array you are recieving an autoreleased array
basic = [NSArray arrayWithObjects:projID, projStat, appDate, closeDate,countryName,regionName,envCatCode,teamLeader,borrower,impAgency,totalCost,comtAmt, nil];
This will most likely be gone by the time you try to access it. You need to add a retain to it or not use an autorelease method
1.
// The preferred way in this instance
basic = [[NSArray alloc] initWithObjects:projID, projStat, appDate, closeDate,countryName,regionName,envCatCode,teamLeader,borrower,impAgency,totalCost,comtAmt, nil];
2.
// Not the best way
basic = [[NSArray arrayWithObjects:projID, projStat, appDate, closeDate,countryName,regionName,envCatCode,teamLeader,borrower,impAgency,totalCost,comtAmt, nil] retain];
Either way it may be handy to read up on your memory management.
It is much easier to use synthesized getters/setters for properties and not accessing the ivars directly unless you really mean to like in init
and dealloc
methods.
Another issue I see (unrelated to the crash) is that you have not initialised the number
to anything and you have not set it in the default
case in the switch statement this could be the cause of a bug that is tricky to track down later on.
Upvotes: 4