2017-12-30 47 views
0

나는 MacOS에 응용 프로그램을 포팅하고 있는데, NITableView로 UITableView를 다시 구현해야한다. 그러나 작동 시키려면 몇 가지 문제가있다.코코아 : UITableView를 NSTableView로 변환 하시겠습니까?

iOS의 내 레이아웃은 기본적으로 log.count (아래 참조)에있는 행 수와 함께 단일 열의 스크롤 가능한 텍스트 셀 목록입니다.

인터페이스 작성기에서 표보기을 기본보기에 추가 한 후 콘텐츠 모드를 "셀 기반"으로 변경하고 열을 "1"로 변경하고 unticked "headers"로 변경했습니다.

다음으로 ViewController에 NSTableViewDelegate & NSTableViewDataSource 프로토콜을 지정하고 두 가지 모두에 대한 대리인으로 설정 한 다음 테이블보기의 콘센트를 설정합니다.

나는 단지 3 개 기능의 NS 버전을 구현할 필요가 바라고 있어요 :

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
UITableView.reloadData() 

다른 모든 매우 간단한다. 참고로

이 내 아이폰 OS가 jQuery과 콘센트와 컨트롤러를 볼 수 있습니다 : 사전에

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

    @IBOutlet weak var tableView: UITableView! 

    var log = ["Welcome!"] 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return log.count 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell") 
     cell.textLabel?.text = log[indexPath.row] 
     return cell 
    } 

    func appendToLog(string: String) { 
     log.append(string) 
     tableView.reloadData() 
    } 

} 

감사합니다!

+0

가정 희망, [Mac 용 테이블보기 프로그래밍 가이드] (읽기하지 마십시오 https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/TableView/Introduction/Introduction.html). – Willeke

답변

-2
class ViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource { 

    @IBOutlet weak var tableView: NSTableView! 

    var log = ["Welcome!"] 

    func numberOfRows(in tableView: NSTableView) -> Int { 
     return log.count 
    } 

    func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { 
     let cell = NSTextFieldCell(textCell: log[row]) 
     return cell 
    } 

    func appendToLog(string: String) { 
     log.append(string) 
     tableView.reloadData() 
    } 

}