2016-11-11 19 views
2

在这个代码我加上程序上的VC:出队可重复使用的电池老是死机

@IBAction func addPerson(_ sender: UIBarButtonItem) { 
     let controller = CNContactPickerViewController() 
     controller.delegate = self 
     navigationController?.present(controller, animated: true, completion: nil) 
    } 

这里我使用去另一个VC当我在接触点击(显示信息进入细胞,然后我想使对于手机/电子邮件复选框,显示早在我的第一个VC)

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) { 
     let vc = EditContactViewController() 
     self.navigationController?.pushViewController(vc, animated: true) 

我创建了一个类下一个单元格和我成立了标识为故事板 细胞时,我这样做是的tableView的cellForRowAtIndexPath

let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? ConfigCell 

return cell! 

这给了我:

fatal error: unexpectedly found nil while unwrapping an Optional value 

我也尝试withIdentifier,forIndexPath和它说:

二○一六年十一月一十二日01:35:28.626 iEvents3 [2637:47714] ** *终止应用到期应用 未捕获异常'NSInternalInconsistencyException',原因: '无法使带标识符单元的单元出列 - 必须注册一个笔尖 或标识符的类或连接 故事板'

我删除了重用标识符并将其重新放回,清理应用程序,重新启动一切。

谢谢你的时间!

回答

1

就不可能有这几个原因:

  1. 如果您有UITableViewCell在控制器本身,然后检查重用标识符是否被设置为"cell"

  2. 如果你有你的UITableViewCell单独.xib,然后

    一)注册与您的表视图单元格的笔尖在控制器的viewDidLoad()

    self.tableView.register(UINib(nibName:"CustomTableViewCell"), forCellWithReuseIdentifier: "cell") 
    

    注册.nib只有当你确信table viewoutlet设置。否则,如果outlet如果table view仍然是nil,它将不会注册您的手机的.nib

    b)检查重用标识符是否设置为"cell"

+0

我解决了这个问题: 设V = self.storyboard .instantiateViewController(withIdentifier: “帮助”)? self.navigationController .pushViewController(V!动画:真) 在故事板,我把故事板标识符包括v控制器“帮助” –

1

您是否将该单元格作为xib?你把你的单元格添加到表格视图中了吗?试试这个,如果是这样的话

@IBOutlet weak var tableView: UITableView! 

    override func viewDidLoad() { 
self.tableView.register(UINib(nibName: "ConfigCell",bundle: nil), forCellReuseIdentifier: "cell") 
} 
+0

no。它没有工作。 我添加了故事板中的所有内容 –

+0

你做了*代码**和故事板中的**都注册吗? – Honey

0

当细胞展开它崩溃的应用程序

FUNC的tableView(_的tableView:SLExpandableTableView!,willExpandSection部分:UINT,动画:布尔) {

} 

func tableView(_ tableView: SLExpandableTableView!, didExpandSection section: UInt, animated: Bool) 
{ 
    let indexPath = IndexPath(row: 0, section: Int(section)) 
    let cell: SLExpandableHeaderCell = (tableView.cellForRow(at: indexPath) as! SLExpandableHeaderCell) 

    cell.empProfImage?.image = UIImage(named: "upArrowGrey.png") 

    //  let imgCategorySymbol: UIImageView = (cell.viewWithTag(5030) as! UIImageView) 
    //  imgCategorySymbol.image = UIImage(named: "upArrowGrey.png") 

    for i in 0..<arrCategoriesServices.count 
    { 
     if !selectedSectionIndex.contains("\(i)") && i != Int(section) { 

      tableView.collapseSection(i, animated: true) 
     } 
    } 
} 

func tableView(_ tableView: SLExpandableTableView!, willCollapseSection section: UInt, animated: Bool) { 
    let indexPath = IndexPath(row: 0, section: Int(section)) 

    let cell: SLExpandableHeaderCell = (tblExpandableView.cellForRow(at: indexPath) as! SLExpandableHeaderCell) 
    cell.empProfImage?.image = UIImage(named: "downArrowGrey.png") 

    //  let imgCategorysymbol: UIImageView? = (cell.viewWithTag(5030) as! UIImageView) 
    //  imgCategorysymbol?.image = UIImage(named: "downArrowGrey.png") 
} 

func tableView(_ tableView: SLExpandableTableView, canChangeSection section: Int) -> Bool { 
    if collapsingSection != section { 
     return true 
    } 
    else { 
     return false 
    } 
} 

func tableView(_ tableView: SLExpandableTableView!, didCollapseSection section: UInt, animated: Bool) { 

} 

func tableView(_ tableView: SLExpandableTableView, canExpandSection section: Int) -> Bool 
{ 
    return true 
} 


func tableView(_ tableView: SLExpandableTableView!, needsToDownloadDataForExpandableSection section: Int) -> Bool 
{ 
    return false 
} 

func tableView(_ tableView: SLExpandableTableView!, expandingCellForSection section: Int) -> UITableViewCell 
{ 
    var cell: SLExpandableHeaderCell! 

    if cell == nil 
    { 
     cell = tblExpandableView.dequeueReusableCell(withIdentifier: headerCell) as! SLExpandableHeaderCell 
    } 


    let label = UILabel() 
    label.frame = CGRect(x: CGFloat(10), y: CGFloat(10), width: CGFloat(100), height: CGFloat(25)) 
    cell.addSubview(label) 


    cell.empProfImage?.image = UIImage(named: "downArrowGrey.png") 
    cell?.selectionStyle = .none 

    let cat: CategoryModel = (arrCategory[section] as! CategoryModel) 
    label.text = cat.categoryName 
    print("Expanding table for categoty : \(cat.categoryName)") 
    // cell.textLabel?.frame = frame 
    // cell?.textLabel?.text = cat.categoryName 

// Util.setCategoryDe​​tailFontColorAndSize(标签:?!(细胞.textLabel)!LabelText的:cat.categoryName) Util.setCategoryDe​​tailFontColorAndSize(标签:标签,LabelText的:? '!' cat.categoryName) 细胞.textLabel .backgroundColor = UIColor.clear

return cell! 
} 

public func tableView(_ tableView: SLExpandableTableView!, downloadDataForExpandableSection section: Int) 
{ 

} 
+0

应用程序在此行上崩溃let cell:SLExpandableHeaderCell =(tblExpandableView.cellForRow(at:indexPath)as!SLExpandableHeaderCell) –

1

确保没有登录接口插座连接

enter image description here