在 UITableViewController 子类中,我无法加载数据,我正在从 Url 获取 json 数据,
json数据:
{
"terms": "a",
"results": {
"Events": [
{
"Event_Name": "808 State",
"Event_NavigateURL": "808-state"
},
{
"Event_Name": "ASAP Rocky",
"Event_NavigateURL": "asap-rocky"
},
{
"Event_Name": "Abba Mania",
"Event_NavigateURL": "abba-mania"
},
{
"Event_Name": "Adam Ant",
"Event_NavigateURL": "adam-ant"
}
],
"Sports": [
{
"SportsName": "Arsenal",
"URL": "football/arsenal-tickets.htm",
"SubCategory_NavigateURL": "football",
"Event_NavigateURL": "arsenal",
"type": "team"
},
{
"SportsName": "Aston Villa",
"URL": "football/aston-villa-tickets.htm",
"SubCategory_NavigateURL": "football",
"Event_NavigateURL": "aston-villa",
"type": "team"
},
{
"SportsName": "Fulham",
"URL": "football/fulham-tickets.htm",
"SubCategory_NavigateURL": "football",
"Event_NavigateURL": "fulham",
"type": "team"
},
{
"SportsName": "Manchester City",
"URL": "football/manchester-city-tickets.htm",
"SubCategory_NavigateURL": "football",
"Event_NavigateURL": "manchester-city",
"type": "team"
}
],
"Venues": [
{
"Venue": "O2 Arena London",
"Venue_LocationURL": "o2-arena-london",
"Venue_City": "London",
"Venue_Country": "United Kingdom",
"Venue_CountryURL": "united-kingdom"
},
{
"Venue": "The Odyssey Arena",
"Venue_LocationURL": "the-odyssey-arena",
"Venue_City": "Belfast",
"Venue_Country": "United Kingdom",
"Venue_CountryURL": "united-kingdom"
},
{
"Venue": "Manchester Arena",
"Venue_LocationURL": "manchester-arena",
"Venue_City": "Manchester",
"Venue_Country": "United Kingdom",
"Venue_CountryURL": "united-kingdom"
},
{
"Venue": "SECC Clyde Auditorium",
"Venue_LocationURL": "secc-clyde-auditorium",
"Venue_City": "Glasgow",
"Venue_Country": "United Kingdom",
"Venue_CountryURL": "united-kingdom"
}
]
}
}
这是我的代码片段,
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dict count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewcellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text= [[[dict valueForKey:@"results"] valueForKey:@"Sports"] valueForKey:@"Event_NavigateURL"];
cell.detailtextLabel.text= [[[dict valueForKey:@"results"] valueForKey:@"Sports"] valueForKey:@"type"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
newViewController *obj=[[newViewController alloc]init];
obj.str=[[[[dict valueForKey:@"results"] valueForKey:@"SportsName"] valueForKey:@"Event_NavigateURL"] valueForKey:indexPath.row];
[self.navigationController pushViewController:obj animated:YES];
}
NSDictionary 应该如何与 TableView 一起工作?
完成这项工作的最简单方法是什么?