채팅 앱에 대한 두 가지보기가 있습니다.
하나는 ChatListView (tableview)이고 다른 하나는 ChatDetail입니다. ChatListView 클래스에서 이 예기치 않게 발견되었습니다. iOS 용 Swift에서 선택적 값을 래핑하지 않았습니다.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.dequeueReusableCellWithIdentifier("ChatCell") as! ChatListCell
if let rvc = self.storyboard?.instantiateViewControllerWithIdentifier("ChatDetail") as? ChatDetail{
rvc.managedObjectContext = self.managedObjectContext
//here is the error occur "unexpectedly found nil while unwrapping an Optional value"
rvc.counter = cell.chatUserName?.text!
rvc.title = cell.chatUserName?.text!
}
}
의 ChatDetail에서
class ChatListCell: UITableViewCell {
@IBOutlet weak var chatUserName: UILabel!
@IBOutlet weak var lastMessage: UILabel!
@IBOutlet weak var lastDate: UILabel!
}
, 나는 다음과 같은 couner을 선언했다.
class ChatDetail: JSQMessagesViewController, NSFetchedResultsControllerDelegate {
var counter: String?
}
시도했습니다 (cell.chatUserName?. 텍스트!)! Xcode 권장처럼. 그러나 같은 오류가 발생합니다.
사용해야합니까? '셀'을 큐에서 꺼낼 때 또는 텍스트 속성에 액세스 할 때? –
항상 그렇듯이 ** 뷰 (테이블 뷰 셀)에서 데이터를 검색하지 않고 모델 (데이터 소스 배열) – vadian