views:

296

answers:

1

Hey guys, i've got a problem debugging an iphone app that i'm attempting to write and it's got me stumped, bear with me, i'm a n00b to programming and might get some of the terminology wrong but i'll try to explain it as best as i can.

The app gets an XML doc from the a web site, parses it into an array, and then displays it in a table view, i have the parser in a separate file. The ViewDidLoad in RootViewController sends it a url, the parser goes to work and then returns an NSMutableArray.

When i run the app it works fine with small XML files (5 entries or so, and 1-3 sections), but when i use a larger one(20+ rows, over 12 sections) i get the error "-[CFString length]: message sent to deallocated instance 0x3881940" when i scroll near the bottom of the tableview, just as the last section title is about to come onto the viewable area on the screen to be precise.

if i return a static string instead of the object in my array in this method it doesn't crash, but i can use NSLog to call the array and it returns the title no problems.

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)indexPath {
    return [[returnedEvents objectAtIndex:indexPath ] objectAtIndex:0];
}

The returnedEvents array isn't released until -(void) dealloc {}

I have read a few other posts on here, and a few guides on debugging and as of yet am unable to find anything that was able to help me, i'd be more than happy to post some code up here and any more information, i'm just not sure where to start...

Thanks in advance for anyone willing to have a go at helping me out.

** Update

Here is the Cell View Code.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

// Configure the cell.
[[cell detailTextLabel] setText:[[[returnedEvents objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1] objectForKey:@"Summary"]];
[[cell textLabel] setText:[[[returnedEvents objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1] objectForKey:@"title"]];

return cell;
}

*Another Update

This is what comes up in the debugger when the program crashes, i am to understand from my meanderings through some debugging tutorials that this is the stack trace, if it looks wrong just let me know.

#0  0x01be33a7 in ___forwarding___
#1  0x01bbf6c2 in __forwarding_prep_0___
#2  0x00066f13 in -[UITableView(UITableViewInternal) _delegateWantsHeaderForSection:]
#3  0x00069fe2 in -[UITableView(_UITableViewPrivate) _updateVisibleHeadersAndFootersNow]
#4  0x000727e4 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow]
#5  0x00069953 in -[UITableView layoutSubviews]
#6  0x02f482b0 in -[CALayer layoutSublayers]
#7  0x02f4806f in CALayerLayoutIfNeeded
#8  0x02f478c6 in CA::Context::commit_transaction
#9  0x02f4753a in CA::Transaction::commit
#10 0x02f4f838 in CA::Transaction::observer_callback
#11 0x01bbb252 in __CFRunLoopDoObservers
#12 0x01bba65f in CFRunLoopRunSpecific
#13 0x01bb9c48 in CFRunLoopRunInMode
#14 0x01d6078d in GSEventRunModal
#15 0x01d60852 in GSEventRun
#16 0x00023003 in UIApplicationMain
#17 0x00002a20 in main at main.m:14

This is the code i use to get the array:

NSURL *XMLURLPath = [[NSURL alloc] initWithString:@"http://www.localendar.com.au/events/database_xml.php?day=2010-05-01&endday=2010-05-30"];
returnedEvents = [[NSMutableArray alloc] initWithArray:[localoXMLParser parseXMLDataWithURL:XMLURLPath]];   
[XMLURLPath release];

Perhaps this is bad practice? The array is a few levels deep, is it possible that the app is releasing some of the objects within the array somehow?

A: 

Can't see anything wrong with the code, but here is what we can determine from the information you gave.

The error indicates that somewhere the code is failing as a request of length is being sent to a released string (having the stacktrace would help).

The fact that it works with ~5 looks like it may be to do with the dequeueing of cells as you scroll.

When you iterate through the array and access all the members, I presume this is in the cellForRowAtIndexPath and you are logging the text when you scroll? If so, then the array is also fine.

Could it have something to do with the indexPath.row + 1, do you have an extra cell that you use to store some other data?

Liam
Hey Liam, thanks for taking the time to answer. The array holds a list of local events, sorted into smaller arrays that hold events on a given date, the first object in each dateArray is an NSString that contains the date, which is used for the title of a tableSection, `indexPath.row + 1` just skips this entry to start pulling data from the NSMutableDictionarys that hold the information for each event. Short answer. It's meant to be there.
Hockey
If you get a chance, put up the stacktrace and I'll have a look. It may give more pointers
Liam