【发布时间】:2017-09-02 12:33:35
【问题描述】:
我创建了显示城市列表的简单表视图。然后我创建了初始化城市对象的简单城市类。然后在视图控制器中,我从 cityArray 中的 url 检索数据。然后将该数组显示到表视图中。然后我使用此函数将选定的行数据发送到详细 ViewController
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *dvc=[[DetailViewController alloc] init];
//retrive the current selected city
City *currentCity=[cityArray objectAtIndex:indexPath.row];
dvc.name=currentCity.cityName;
dvc.population=currentCity.cityPopulation;
dvc.country=currentCity.cityCounrty;
[self.navigationController pushViewController:dvc animated:YES];
}
1- 我希望城市列表应在副标题中显示相应国家/地区列表,我跟随此功能的更改,但它不起作用
-(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=[NSString stringWithFormat:@"Cell %d",indexPath.row];
// retrieve the current city object for use with this indexpath.row
City *currentCity=[cityArray objectAtIndex:indexPath.row];
cell.textLabel.text=currentCity.cityName;
cell.detailTextLabel.text=currentCity.cityCounrty;
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
2- 当用户点击城市列表中的 tableview 单元格时,我想要。表格视图应该在 DetailViewController 中显示城市的相应详细信息。但是 DetailViewController 显示黑屏。我怎样才能删除这个后屏并获取实际记录? 您可以从此链接下载示例项目进行更正。https://drive.google.com/file/d/0B5pNDpbvZ8Snd3lhVFpZTWJveVU/view?usp=sharing
【问题讨论】:
-
你需要使用 [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"] 实例化你的 DetailViewController
-
我已经尝试在这些链接上给出答案。但没有一个有效.stackoverflow.com/questions/14929039/…...stackoverflow.com/questions/22259246/…..stackoverflow.com/questions/41407841/…
-
您是否在情节提要中为 DetailViewController 指定了标识符?
标签: ios objective-c iphone uitableview