我从 Web 服务 API 得到响应,如下所示:
{
"springs": [{
"name": "springName",
"leafs": [{
"name": "leafName",
"towns": [{
"name": "townName",
},{
"name": "leafName2",
},{
我Leafs在LeafViewController表格视图中列出所有的,如果Leaf有一个Towns与之关联的列表,那么它会转到TownViewController表格视图来列出关联的Towns.
我的所有这些都是正确的cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"standardCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Spring *spring = [springs objectAtIndex:indexPath.section];
Leaf *leaf = [sport.leafs objectAtIndex:indexPath.row];
cell.textLabel.text = leaf.shortName;
return cell;
}
我的问题是,有时没有Town与 a 相关联Leaf,在这种情况下,我需要检查一下,因此如果Leaf按下该单元格,那么我可以弹回主视图控制器,而不是转到列出Towns 的下一个视图控制器。
现在,如果我选择一个Leaf没有Towns 关联的单元格,那么它会选择TownViewController空白的,因为没有关联的城镇。
我将如何检查 JSON 响应,以便知道是继续到下一个 TownViewController 还是弹回MainViewController?
我可以发布任何必要的额外代码,感谢您的帮助!