簡體   English   中英

Segue導致黑屏

[英]Segue lead to black screen

我創建了一個顯示城市列表的簡單表格視圖,然后創建了一個初始化城市對象的簡單城市類,然后在viewcontroller中從cityArray中的url檢索了數據,然后將該數組顯示到了tableview中。 然后我使用此功能將選定的行數據發送到詳細信息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

您在這行做錯了

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

每當您使用情節提要板並嘗試推送Viewcontroller時,都需要在StoryBoard中為控制器提供一個標識符,而不是執行alloc init。

只需用此行替換您的alloc init,它將對您有用。

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

是的,請確保在StoryBoard中提供標識符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM