我有一個UITableViewController,它有一個從原型單元連接到一個詳細頁面的常規舊UIViewController的故事板push segue。在故事板中,ViewController的詳細信息有一個標識符,而segue的標識符與詳細標識符相同,只是第一個字母是小寫。此外,ViewController的詳細信息在類下拉菜單中選擇了一個「自定義類」(AttractionDetailViewController
)。Objective-C,故事板:instantiateViewControllerWithIdentifier返回無
不起作用。問題是instantiateViewControllerWithIdentifier:@"AttractionDetails
返回nil
。
相關代碼。首先調試器從未輸入過的方法prepareForSegue
。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"attractionDetails"])
{
AttractionDetailViewController *attrDetailVC = [segue destinationViewController];
}
}
相反,它進入這個方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//AttractionDetailViewController *attrDetailVC = [[AttractionDetailViewController alloc] init];
AttractionDetailViewController *attrDetailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"AttractionDetails"];
NSIndexPath *selIndexPath = [self.tableView indexPathForSelectedRow];
attrDetailVC.theAttraction = [attractions objectAtIndex:indexPath.row];
[self.navigationController pushViewController:attrDetailVC animated:YES];
}
由於instantiateViewControllerWithIdentifier
回報nil
它拋出當然是一個例外。真正有趣的是,如果我使用alloc init
行,它可以工作,但屏幕全是黑色的。
無論如何,我已經讀過這個,並嘗試了一些不同的東西,我仍然困難。有沒有人有什麼建議?
嗯,它其實是。我甚至沒有想過要檢查,因爲我以某種方式「自我」(這是從根導航控制器開始的第三個視圖)。我嘗試了這個,而它似乎做了詭計:'UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@「MainStoryboard」bundle:[NSBundle mainBundle]];'。謝謝! –