开发者

Why won't my UITableView show the data?

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 h开发者_开发技巧ave 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.


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].


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜