Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当我点击我的详细信息披露按钮时,我的应用程序崩溃了_Ios_Iphone_Xcode_Swift - Fatal编程技术网

Ios 当我点击我的详细信息披露按钮时,我的应用程序崩溃了

Ios 当我点击我的详细信息披露按钮时,我的应用程序崩溃了,ios,iphone,xcode,swift,Ios,Iphone,Xcode,Swift,我创建了一个类似于Requires的应用程序,但每当我点击detail Exposition编辑现有列表名的名称时,它就会突然使应用程序崩溃。我在类中编写了accessoryButtonTappedForRowWithIndexPath代码。下面是我的accessoryButtonTappedForRowWithIndexPath方法的代码 override func tableView(tableView: UITableView, accessoryButtonTappedForRowWit

我创建了一个类似于Requires的应用程序,但每当我点击detail Exposition编辑现有列表名的名称时,它就会突然使应用程序崩溃。我在类中编写了accessoryButtonTappedForRowWithIndexPath代码。下面是我的accessoryButtonTappedForRowWithIndexPath方法的代码

override func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath)
{
    let navigationController = storyboard!.instantiateViewControllerWithIdentifier("ListDetailViewController") as! UINavigationController

    let controller = navigationController.topViewController as! ListDetailViewController

    controller.delegate = self

    let checklist = dataModel.lists[indexPath.row]

    controller.checklistToEdit = checklist

    presentViewController(navigationController, animated: true, completion: nil)
    }

您的应用程序正在崩溃,因为其中一个变量为零:

  • 故事板
  • navigationController.topViewController
或者您在这里得到了一个
索引超出范围的
错误

dataModel.lists[indexPath.row]
从代码中也不明显,如果这一行:

storyboard!.instantiateViewControllerWithIdentifier("ListDetailViewController") as! UINavigationController
确实做了它应该做的事情,因为字符串显示,您想要一个ListDetailViewController,但您将函数的结果强制转换为一个
UINavigationViewController
,这也可能导致崩溃

要修复崩溃并了解发生了什么,请像这样重写代码(仅用于测试目的,因为此代码很难看):

如果让navigationController=storyboard?。实例化eviewcontrollerwhiteIdentifier(“ListDetailViewController”)为!导航控制器
{
如果让控制器=navigationController.topViewController作为?ListDetailViewController
{
controller.delegate=self
如果dataModel.list.count

希望这将对您有所帮助。

显示崩溃信息。请检查“ListDetailViewController”是否为Storyboard中导航控制器或ListDetailViewController的标识符无法将“to_do_list.AddItemViewController”类型的值强制转换为“to_do_list.ListDetailViewController”@Jensi认为您使用了错误的标识符“ListDetailViewController“用于导航控制器。请在againI检查完所有连接后登录故事板,但所有连接都已清除@moinuddin girachI不明白这意味着什么我应该给你我的应用程序的全部代码以理解我不理解错误消息。我假设您已经提供了应用程序崩溃的部分。但是如果不理解错误/崩溃消息,我在调试区域就无能为力,它显示了一个错误“以NSException类型的未捕获异常终止”,它发生在哪里?您是否使用我在回答中提供的代码?
if let navigationController = storyboard?.instantiateViewControllerWithIdentifier("ListDetailViewController") as! UINavigationController 
{
  if let controller = navigationController.topViewController as? ListDetailViewController
  {
    controller.delegate = self
    if dataModel.list.count < indexPath.row
    {
      let checklist = dataModel.lists[indexPath.row]
      controller.checklistToEdit = checklist
      presentViewController(navigationController, animated: true, completion: nil) 
    } else 
    {
       println("array out of index")
    }
  } else 
  {
     println("topView Controller of navigation controller is nil")
  }
} else 
{
  println("navigationController or storyboard is nil")
}
 override func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath)
 {
     let controller = self.storyboard?.instantiateViewControllerWithIdentifier("ListDetailViewController") as ListDetailViewController
     controller.delegate = self
     controller.checklistToEdit = dataModel.lists[indexPath.row]
     self.presentViewController(controller, animated: true, completion: nil)
     }