2016-11-11 34 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