Objective-C의 일부 코드를 신속하게 번역하려고합니다. 언제 UITableView 함께보기를 설정에 관해서는 런타임에 오류가 발생하면 즉시보기가로드됩니다. 이유를 이해할 수 없습니다. 나는 SotryBoard에서 테이블 뷰를 가지고 있고 정확히Swift에서 UITableView - 알 수없는 예외
오류
2014년 12월 18일 00 오브젝티브 C의 작업 버전처럼 등 대리자까지 연결된 : 54 : 02.849 앱 Swift [5091 : 282178] *** 캐치되지 않은 예외 'NSUnknownKeyException'로 인해 앱이 종료되었습니다. 이유 : '[ setValue : forUndefinedKey :] :이 클래스는 키 값인 키 tableView에 대해 코딩 호환되지 않습니다.'
코드
import UIKit
class CreationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var mTableView : UITableView?
var counter : NSInteger = 0
override func viewDidLoad() {
super.viewDidLoad()
// counter calculated here
self.mTableView?.dataSource = self
self.mTableView?.delegate = self
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (counter == 0) {
return 1
}
return counter
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellIdentifier", forIndexPath: indexPath) as UITableViewCell
cell.textLabel.text = "TEST"
return cell
}
}
이 오류는 일반적으로 코드에 해당 속성이없는 IB의 콘센트가있어서 발생합니다. IB의 컨트롤러를 마우스 오른쪽 버튼으로 클릭하고 "tableView"라는 콘센트가 있는지 확인하십시오. 그렇다면 연결을 끊으십시오. – rdelmar