I have a UITableView which is setup in Interface Builder and connected properly to its class in Xcode. I also have a "Importer" Class which downloads and parses an RSS feed and stores the information in an NSMutableArray.
However I have verified the parsing is working properly (using breakpoints and NSlog) but no data is showing in the UITable View. Any ideas as to what the problem could be? I'm almost out of them.
It's based on the XML performance Apple example.
Here's the code for TableView.h:
#import <UIKit/UIKit.h>
#import "IncidentsImporter.h"
@class SongDetailsController;
@interface CurrentIncidentsTableViewController : UITableViewController <IncidentsImporterDelegate>{
NSMutableArray *incidents;
SongDetailsController *detailController;
UITableView *ctableView;
IncidentsImporter *parser;
}
@property (nonatomic, retain) NSMutableArray *incidents;
@property (nonatomic, retain, readonly) SongDetailsController *detailController;
@property (nonatomic, retain) IncidentsImporter *parser;
@property (nonatomic, retain) IBOutlet UITableView *ctableView;
// Called by the ParserChoiceViewController based on the selected parser type.
- (void)beginParsing;
@end
And the code for .m:
#import "CurrentIncidentsTableViewController.h"
#import "SongDetailsController.h"
#import "Incident.h"
@implementation CurrentIncidentsTableViewController
@synthesize ctableView, incidents, parser, detailController;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.parser = [[IncidentsImporter alloc] init];
parser.delegate = self;
[parser start];
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(beginParsing)];
self.navigationItem.rightBarButtonItem = refreshButton;
[refreshButton release];
// Uncomment the following line to preserve selection between presentations.
//self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewWillAppear:(BOOL)animated {
NSIndexPath *selectedRowIndexPath = [ctableView indexPathForSelectedRow];
if (selectedRowIndexPath != nil) {
[ctableView deselectRowAtIndexPath:selectedRowIndexPath animated:NO];
}
}
// This method will be called repeatedly - once each time the user choses to parse.
- (void)beginParsing {
NSLog(@"Parsing has begun");
//self.navigationItem.rightBarButtonItem.enabled = NO;
// Allocate the array for song storage, or empty the results of previous parses
if (incidents == nil) {
NSLog(@"Grabbing array");
self.incidents = [NSMutableArray array];
} else {
[incidents removeAllObjects];
[ctableView reloadData];
}
// Create the parser, set its delegate, and start it.
self.parser = [[IncidentsImporter alloc] init];
parser.delegate = self;
[parser start];
}
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [incidents count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Table Cell Sought");
static NSString *kCellIdentifier = @"MyCell";
UITableViewCell *cell = [ctableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = @"Test";//[[incidents objectAtIndex:indexPath.row] title];
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.detailController.incident = [incidents objectAtIndex:indexPath.row];
[self.navigationController pushViewController:self.detailController animated:YES];
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)parserDidEndParsingData:(IncidentsImporter *)parser {
[ctableView reloadData];
self.navigationItem.rightBarButtonItem.enabled = YES;
self.parser = nil;
}
- (void)parser:(IncidentsImporter *)parser didParseIncidents:(NSArray *)parsedIncidents {
//[incidents addObjectsFromArray: parsedIncidents];
// Three scroll view properties are checked to keep the user interface smooth during parse. When new objects are delivered by the parser, the table view is reloaded to display them. If the table is reloaded while the user is scrolling, this can result in eratic behavior. dragging, tracking, and decelerating can be checked for this purpose. When the parser finishes, reloadData will be called in parserDidEndParsingData:, guaranteeing that all data will ultimately be displayed even if reloadData is not called in this method because of user interaction.
if (!ctableView.dragging && !ctableView.tracking && !ctableView.decelerating) {
self.title = [NSString stringWithFormat:NSLocalizedString(@"Top %d Songs", @"Top Songs format"), [parsedIncidents count]];
[ctableView reloadData];
}
}
- (void)parser:(IncidentsImporter *)parser didFailWithError:(NSError *)error {
// handle errors as appropriate to your application...
}
- (void)dealloc {
[super dealloc];
}
@end