NSTableView 获取具有单元格的 indexPath [英] NSTableView get indexPath having the cell

查看:62
本文介绍了NSTableView 获取具有单元格的 indexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用UITableView很容易找到基于单元格的indexPath

tableView.indexPath(for: cell)

但不幸的是,在 MacOS 上,此方法不存在.
我的用例如下:
我在 Cell View 中有一个按钮,点击后我调用委托的 ViewController 来做一些事情.现在我有了单元格的实例,我想要获得的是它在 NSTableView 中的行(位置).我如何获得它?

解决方案

在 macOS 中使用基于视图的表格视图,为按钮创建一个标准的 IBAction 并使用 row(查看:

<块引用>

func row(for view: NSView) ->整数

返回指定视图的行索引.

基于视图的表视图更加通用且易于处理.

With UITableView it's pretty easy to find the indexPath based on a cell using

tableView.indexPath(for: cell)

but on MacOS this method does not exist unfortunately.
My use case is the following:
I have a button in the Cell View and upon click I call the delegated ViewController to do stuff. Now I have the instance of the cell, what I want to obtain is its row (position) in the NSTableView. How can I obtain it?

解决方案

In macOS use a view based table view, create an standard IBAction for the button and get the row with row(for view:

func row(for view: NSView) -> Int

Returns the index of the row for the specified view.

A view based table view is much more versatile and much easier to handle.

这篇关于NSTableView 获取具有单元格的 indexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆