开发者

Return junk value for selectedRow in NSTableView

I have a code which returns selected row for NStableView as under:

int status;
NSUInteger selectedRow = [tableView selectedRow];
if (selectedRow == 0)
    return;

But, when i have no开发者_如何学运维t selected any row in table view or if the tableview is empty, it returns junk value. How can i tackle with this problem.


-selectedRow returns signed integer and you're using unsigned in your code. If there's no row selected method returns -1, so you're getting some overflowed value in your unsigned variable.


The first row in the table is row zero. The placeholder for "no selected row" is NSNotFound.


An alternative solution would be to get the table view's selectedRowIndexes and check the count of that set. An empty index set (count == 0) means no selection; if the index set is not empty (count > 0), at least one row is selected (the rows identified by the indexes in the set).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜