Hi,
My UITableView has up to 50 rows in each section, populated by a plist dictionary which contains arrays (sections) which contains arrays (row objects) which contains two strings (row title / filename and file extension).
Select row 1 - 25 (item 0-24) and everything behaves normally. But select a row greater than 26 (item 25) and the app crashes. I'm a novice at all this and I tried researching for the answer but I'm at a loss for how to research this. Can tables only have 25 rows per section?
Any ideas? Thank you!
Jon
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSMutableString *key = [categories objectAtIndex:section];
NSMutableArray *sound = [categoriesSounds objectForKey:key];
NSMutableString *soundName = [[sound objectAtIndex: row] objectAtIndex: 0];
NSMutableString *soundOfType = [[sound objectAtIndex: row] objectAtIndex: 1];
if (leftSwitch.on == YES) {
showLeft.text = soundName;
left = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL
fileURLWithPath:left], &soundNegZ);
AudioServicesPlaySystemSound (soundNegZ);
if (indexPath != leftOldIndexPath) {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:leftOldIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
leftOldIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
if (downSwitch.on == YES) {
showDown.text = soundName;
down = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL
fileURLWithPath:down], &soundNegX);
AudioServicesPlaySystemSound (soundNegX);
if (indexPath != downOldIndexPath) {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:downOldIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
downOldIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
if (rightSwitch.on == YES) {
showRight.text = soundName;
right = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL
fileURLWithPath:right], &soundPosX);
AudioServicesPlaySystemSound (soundPosX);
if (indexPath != rightOldIndexPath) {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:rightOldIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
rightOldIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
For "EXC_BAD_ACCESS" in the console, this is the debugger output (error trace is marked with asterisks):
0x91a6cec0 <+0000> mov 0x8(%esp),%ecx
0x91a6cec4 <+0004> mov 0x4(%esp),%eax
0x91a6cec8 <+0008> cmp $0xfffeb010,%ecx
0x91a6cece <+0014> je 0x91a6cf35 <objc_msgSend+117>
0x91a6ced0 <+0016> test %eax,%eax
0x91a6ced2 <+0018> je 0x91a6cf1a <objc_msgSend+90>
0x91a6ced4 <+0020> mov (%eax),%edx
0x91a6ced6 <+0022> push %edi
**0x91a6ced7 <+0023> mov 0x20(%edx),%edi**
0x91a6ceda <+0026> push %esi
0x91a6cedb <+0027> mov (%edi),%esi
0x91a6cedd <+0029> mov %ecx,%edx
0x91a6cedf <+0031> shr $0x2,%edx
0x91a6cee2 <+0034> and %esi,%edx
0x91a6cee4 <+0036> mov 0x8(%edi,%edx,4),%eax
0x91a6cee8 <+0040> test %eax,%eax
0x91a6ceea <+0042> je 0x91a6cef5 <objc_msgSend+53>
0x91a6ceec <+0044> cmp (%eax),%ecx
0x91a6ceee <+0046> je 0x91a6cf00 <objc_msgSend+64>
0x91a6cef0 <+0048> add $0x1,%edx
0x91a6cef3 <+0051> jmp 0x91a6cee2 <objc_msgSend+34>
0x91a6cef5 <+0053> pop %esi
0x91a6cef6 <+0054> pop %edi
0x91a6cef7 <+0055> mov 0x4(%esp),%eax
0x91a6cefb <+0059> mov (%eax),%eax
0x91a6cefd <+0061> jmp 0x91a6cf09 <objc_msgSend+73>
0x91a6ceff <+0063> nop
0x91a6cf00 <+0064> mov 0x8(%eax),%eax
0x91a6cf03 <+0067> pop %esi
0x91a6cf04 <+0068> pop %edi
0x91a6cf05 <+0069> xor %edx,%edx
0x91a6cf07 <+0071> jmp *%eax
0x91a6cf09 <+0073> sub $0x4,%esp
0x91a6cf0c <+0076> push %ecx
0x91a6cf0d <+0077> push %eax
0x91a6cf0e <+0078> call 0x91a6d33f <_class_lookupMethodAndLoadCache>
0x91a6cf13 <+0083> add $0xc,%esp
0x91a6cf16 <+0086> xor %edx,%edx
0x91a6cf18 <+0088> jmp *%eax
0x91a6cf1a <+0090> call 0x91a6cf1f <objc_msgSend+95>
0x91a6cf1f <+0095> pop %edx
0x91a6cf20 <+0096> mov 0xe79d961(%edx),%eax
0x91a6cf26 <+0102> test %eax,%eax
0x91a6cf28 <+0104> je 0x91a6cf30 <objc_msgSend+112>
0x91a6cf2a <+0106> mov %eax,0x4(%esp)
0x91a6cf2e <+0110> jmp 0x91a6ced4 <objc_msgSend+20>
0x91a6cf30 <+0112> mov $0x0,%edx
0x91a6cf35 <+0117> ret
0x91a6cf36 <+0118> nopw %cs:0x0(%eax,%eax,1)
My cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [categories objectAtIndex:section];
NSArray *nameSection = [categoriesSounds objectForKey:key];
static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SectionsTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SectionsTableIdentifier] autorelease];
}
cell.textLabel.text = [[nameSection objectAtIndex:row] objectAtIndex: 0];
if (leftSwitch.on == YES){
NSUInteger leftRow = [leftOldIndexPath row];
NSUInteger leftSection = [leftOldIndexPath section];
cell.accessoryType = (row == leftRow && section == leftSection && leftOldIndexPath !=nil) ?
UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
}
if (downSwitch.on == YES){
NSUInteger downRow = [downOldIndexPath row];
NSUInteger downSection = [downOldIndexPath section];
cell.accessoryType = (row == downRow && section == downSection && downOldIndexPath !=nil) ?
UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
}
if (rightSwitch.on == YES){
NSUInteger rightRow = [rightOldIndexPath row];
NSUInteger rightSection = [rightOldIndexPath section];
cell.accessoryType = (row == rightRow && section == rightSection && rightOldIndexPath !=nil) ?
UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
}
return cell;
}