I'm loading data dynamically from an API using a UISearchBar and trying to display it, using something like this:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
NSLog(@"Search Text: %@",[searchBar text]);
[self startSearchingWithText:[searchBar text]];
}
- (void) startSearchingWithText:(NSString *)text {
...
// Go through the list of services and set up a query for the search term
QueryServiceManager *manager = [[QueryServiceManager alloc] initWithServices: services];
// Set up the query
if (![manager addKeyword: text])
NSLog(@"PROBLEM!");
// Execute the query and store the titles in an array
self.data = [[manager makeQuery] copy]; // Returns a NSArray
NSLog(@"%@",self.data);
// Add the items to the tableView
[self.tableView reloadData];
My UITableViewController code is set up to read from self.data, which is initially a NSArray of @"" elements, as such:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
[self.data count];
}
- (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];
}
// Set up the cell...
cell.textLabel.text = [self.data objectAtIndex:indexPath.row];
return cell;
}
All I get when I do this is:
(gdb) continue 2010-02-26 18:43:32.515 iSave[11690:207] ( "Toshiba Satellite L505-GS5037 TruBrite 15.6-Inch Laptop (Black)", "Dell Inspiron 11 11.6-Inch Obsidian Black Laptop (Windows 7 Premium)", "ASUS Eee PC Seashell 1005PE-MU17-BK 10.1-Inch Black Netbook - Up to 11 Hours of Battery Life", "SwissGear Computer Backpack (Red)", "Belkin 36-Piece Demagnatized Computer Tool Kit with Case (Black)", "Compaq EVO N610C", "Belkin F8E062 55-Piece Computer Tool Kit with Black Case (Demagnetized Tools)", "ASUS Eee PC Seashell 1005PE-PU17-BK 10.1-Inch Black Netbook - Up to 14 Hours of Battery Life", "Harman Kardon SoundSticks II 2.1 Plug and Play Multimedia Speaker System", "ION Audio VCR 2 PC USB VHS Video to Computer Converter" ) (gdb) continue Program received signal: “EXC_BAD_ACCESS”. (gdb)
Any ideas? It looks like the NSArray is being populated properly, then things are failing on/after the reloadData call (breakpoints confirm this, but can't isolate where things are going wrong)
EDIT: I replaced the NSLog() with enumeration (for ( NSString *elem in self.data ) NSLog(elem);), and it still crashes. I managed to coax a log out of it: http://pastebin.com/NDVKLsJC
When I remove the NSLog() entirely, it doesn't crash, but the TableView doesn't update, either.