获取NSOutlineView中的行数

Jos*_*hua 2 cocoa objective-c

如何获得NSOutlineView中的总行数?

Mic*_*ael 7

有一个名为numberOfRows的方法,它返回一个NSInteger.例如你的NSOutlineView被称为outlineView:

NSInteger *rows = [outlineView numberOfRows];
Run Code Online (Sandbox Code Playgroud)

文档在这里:

https://developer.apple.com/documentation/appkit/nstableview/

"通常你不应该询问表格查看它有多少行;相反,你应该询问表格视图的数据源."

有一个非正式的协议,如果你真的坚持使用tableView,它是:

– numberOfRowsInTableView: (NSTableDataSource informal protocol)
Run Code Online (Sandbox Code Playgroud)