【问题标题】:Segue lead to black screenSegue导致黑屏
【发布时间】: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

【问题讨论】:

标签: ios objective-c iphone uitableview


【解决方案1】:

你在这行做错了

 DetailViewController *dvc = [[DetailViewController alloc] init];

每当您使用情节提要并尝试推送视图控制器时,您需要在情节提要中为控制器提供一个标识符,而不是执行 alloc init。

只需将你的 alloc init 替换为这一行,它就会为你工作。

DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];

是的,请确保您在 StoryBoard 中提供标识符。

【讨论】:

  • @Wwwwwwwwwww 我的解决方案是否解决了您的问题?如果是,您可以投票并将其标记为答案。它可能会帮助其他人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 2012-03-20
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多