私はセルから離したときにfatal error: unexpectedly found nil while unwrapping an Optional value
を取得しています。ここでprepareForSegueは最初にnilを返します
コードです:あなたはselectedIngredient
版画二回、見ることができるように
selectedIngredient
nil
selectedIngredient
Optional(Ingredient {
name = Rye Whiskey;
inStock = 1;
type = IngredientType {
name = Spirit;
};
})
fatal error: unexpectedly found nil while unwrapping an Optional value
:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == 1 {
let listIngredients = recipeItem.ingredients[indexPath.row]
selectedIngredient = listIngredients.ingredient
}
tableView.deselectRowAtIndexPath(indexPath, animated: false)
performSegueWithIdentifier("showIngredientInRecipe", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showIngredientInRecipe" {
let svc = segue.destinationViewController as! UINavigationController
let destination = svc.topViewController as! IngredientDetailViewController
destination.ingredientItem = selectedIngredient
print("selectedIngredient \n \(selectedIngredient)")
}
}
ここで私は、デバッガから何を得るのです。最初は無制限で、期待されるコンテンツで2回目です。私がdestination.ingredientItem = selectedIngredient
をdestination.ingredientItem = recipeItem.ingredients[0].ingredient
に置き換えた場合、segueはエラーなしで正常に動作します。
プレゼンテーションの進行中にを表示しようとすると、[prepareForSegueが2回呼び出される可能性があります]の重複の可能性があります(http://stackoverflow.com/questions/14940738/prepareforsegue-getting-called-twice-with-attempt-to -present-uinavigationcontr) –
Dima
「[致命的なエラー:任意の値をアンラッピングしている間に予期せぬエラーが発生しました」とはどういう意味ですか?](http://stackoverflow.com/questions/32170456/what-does-fatal-error-nexpectedly -found-nil-while-unwrapping-an-optional-valu) – Cristik