views:

40

answers:

4

Here is my issue. I have a screen in a tab bar application that display's a search bar, and a UITableView. When you first open the tab, the UITableView is empty. After you enter a search, the iphone gets and parses XML based on the query.

All of this is working fine. I add the xml data to the underlying array that SHOULD populate the table. I have verified that the array contains the data, and is not null. The UITableView remains blank after I search. Any help?

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
//test line
NSLog(@"%@",searchBar.text);
NSString *criteria = [[NSString alloc] initWithString:searchBar.text];

//Parse xml
NSString *uidString = @"55555";

NSString *varString = [[NSString alloc] initWithFormat:@"qryid=4&uid=%@&Criteria=%@",uidString,criteria];
NSString *urlString = [[NSString alloc] initWithString:@"http://services.auctiontrac.com/websvc.asp"];
NSString *parsingString = [[NSString alloc] initWithFormat:@"%@?%@",urlString,varString];
xmlSearch = [[XMLSearch alloc] loadXMLByURL:parsingString];

//init array for table
tableArray = [[NSMutableArray alloc] init];

carTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
[carTable reloadData];

//Add search results to UITableView 
for (Car *c in [xmlSearch cars]) {
    [tableArray addObject:c.make];
    NSLog(@"Added item with make: %@",c.make);
}
[searchBar resignFirstResponder];   
}

Let me know If you need more code to answer this question.

A: 

Have you set the datasource of the table? Try doing that.

arclight
In interface builder? Can you be more specific? I'm a noob to iPhone programming.
Liam
since you're creating it from code IB won't have any effectcheck the UITableView reference and/or download the samples apple provides if you want more info.
arclight
A: 

The table that you are creating is never added to the view so it would never appear. Also, you should have initialized the table and added it to the view outside of this method and then simply call reloadData on it after searching.

cory.m.smith
A: 

Hi,

You have to add carTable in your view i.e. [self.view addSubview: carTable];

and set datasource & delegate of carTable i.e.

carTable.datasource = self;
carTable.delegate = self;

And if you gave put tableview though Interface builder then no need for

carTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];

just set datasource & delegate of table and make outlet of table

i.e. IBoutlet UiTableView *carTable;

and connect it in Interface builder with your table

Reena
+1  A: 

Please make sure that you've set the dataSource for your UITableView and that you call -reloadData on your table view after you've updated the array that holds your data.

Calling -reloadData will prompt the table view to ask its data source for the number of sections, number of rows in each section, and UITableViewCells for the data that's currently visible. I assume your data source methods get the number of rows and data for each row from tableArray. That would mean that tableArray has to contain the latest data when you call [carTable reloadData].

Thomas Müller