보기 기반 테이블을 활용하면 빈 데이터 집합이 있음을 알 때 셀보기를 바꿀 수 있습니다. 트릭은 테이블을 배열에 바인딩하고 비어있는 대신 하나의 항목 표시기를 갖는 것입니다.
내가 여기 당신을 위해 샘플 프로젝트를 생성 :
https://github.com/emankovski/nstableview-empty-picture
그러나 일반적으로 논리가 실제로 매우 간단하다 : 나는 펜촉에 NSTableCellView 객체를 생성하고 내가 어떤 데이터의 표시를 볼 때 그냥 돌아갑니다. 또한 텍스트가있는 셀보다 이미지 길이가 더 긴 셀을 테이블 뷰의 행 높이로 변경합니다. 나는 그것이 도움이되기를 바랍니다. 스토리 보드에 대한
class AppDelegate: NSObject, NSApplicationDelegate, NSTableViewDataSource {
private static let placeholder = "<Placeholder>"
dynamic var items = [String]()
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var tableView: NSTableView!
@IBOutlet weak var imageCell: NSTableCellView!
@IBAction func addRowsPressed(sender: AnyObject) {
appendItems()
}
@IBAction func clearTablePressed(sender: AnyObject) {
removeItems()
}
func applicationDidFinishLaunching(aNotification: NSNotification) {
appendItems()
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
func appendItems() {
items.removeAll()
items.append("One")
items.append("Two")
items.append("Three")
tableView.rowHeight = 20
}
func removeItems() {
items.removeAll()
tableView.rowHeight = 50
items.append(AppDelegate.placeholder)
}
func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
if items[row] == AppDelegate.placeholder {
return imageCell
}
let cellView = tableView.makeViewWithIdentifier("CellView", owner: nil) as! NSTableCellView
return cellView
}
}
UPDATE : 스토리 보드에서 컨트롤러를 볼 수 테이블 셀보기를 드래그하는 방법 사진 :
그럼 그냥 콘센트에 객체 드래그를 연결 콘센트를 작성하고
:
@IBOutlet var tableCellView: NSTableCellView!
유망 해 보입니다. storyboard 아니라 xib 사용하고, cellView 및 imageView간에 테이블 열을 전환 할 수있는 방법이 있나요? 이미지 셀을 내 열로 끌어 왔지만 기존 텍스트 셀을 바꿉니다. – Ravi
오브젝트 라이브러리에서 테이블이 아닌 테이블 뷰 (이미지 또는 텍스트)를 뷰 컨트롤러가 나열된 문서 아웃 라인 영역으로 드래그하십시오. 드래그하여 컨트롤러의 형제가되도록하십시오. –
스토리 보드 지침에 따라 답변을 업데이트합니다. –