셀이있는 테이블 뷰 컨트롤러가 있습니다. 셀을 클릭하면 또 다른보기 컨트롤러가로드되고이보기 컨트롤러에서 요소를 처리하려고합니다. 자세히보기 컨트롤러에서 레이블을 배치하고 첫 번째 단계에서 레이블의 텍스트를 설정하려고하지만 예외가 발생합니다. fatal error: unexpectedly found nil while unwrapping an Optional value
및 이유를 모르겠습니다. 어떤 해결책이 있습니까?신속한 테이블 뷰 컨트롤러의 세부 정보 페이지 처리
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let vcMissionDetail : ViewControllerMissionDetail = self.storyboard?.instantiateViewControllerWithIdentifier("MissionDetail") as ViewControllerMissionDetail;
//load detail view controller
self.presentViewController(vcMissionDetail, animated: true, completion: nil)
//set label text
//at this line I get the exception -> label is nil
vcMissionDetail.label.text = "Test"
}
그리고 이것은 내 상세보기 컨트롤러 (매우 간단)입니다 :
이 셀을 클릭하면 내 테이블 뷰 컨트롤러의 일부입니다
import UIKit
class ViewControllerMissionDetail: UIViewController {
@IBOutlet var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
THX!
오류 지점을 수행하는 코드의 어떤 라인에? –
label이 nil이므로 오류가 발생합니다. 스토리 보드에있는 라벨을 UILabel에 연결하는 것을 잊었습니까? –
'vcMissionDetail.label.text = "Test"'줄에 예외가 있습니다. 그리고 나는 또한 'label' 변수로 스토리 보드의 상세보기 컨트롤러에서 레이블을 참조했습니다 ('@IBOutlet var label : UILabel!'참조) – Martin