Hi all,
I've got some problems to keep the values in an array-property:
There is an UITableViewController which has an property books:
Code:
@property (nonatomic, retain) NSArray *books;
In it's loadView method the UITableViewController requests some data from a webservice (which is a class by its own, referenced in the ApplicationDelegate). When the webservice has finished his asynchronous request he calls back a method on the UITableViewController, delivering a piece of XML:
Code:
- (void)didGetBooksForController:(GDataXMLElement *)returnNode {
NSArray *booksXML = [returnNode elementsForName:@"item"];
//NSLog(@"%@", returnNode);
self.books = [NSArray array];
for (GDataXMLElement *bookXML in booksXML) {
NSLog(@"%@", bookXML);
Book *aBook = [[Book alloc] initWithXML:bookXML];
self.books = [self.books arrayByAddingObject:aBook];
[aBook release];
}
[self.tableView reloadData];
}
All works fine - the returnNode XML holds the data I was looking for, the array holds the number of objects I expected.
The last line in the previous method initiates the UITableView to ask his delegate (my UITableViewController) to provide him with data for the cells:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
NSUInteger section = [indexPath section];
if (books != nil) {
switch (section) {
case 0: {
Book *aBook = [self.books objectAtIndex:row] ;
cell.textLabel.text = aBook.mediatitle;
[aBook release];
break;
}
case 1:
cell.textLabel.text = @"Scenario";
break;
default:
break;
}
}
return cell;
}
but unfortunatly the property self.books seems to be gone!
I'am sure I've got some issues with my retainCount, but I can't figure out which variable to retain without leaving memory unreleased.