views:

20

answers:

3

Hi All,

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 not selected any row in table view or if the tableview is empty, it returns junk value. How can i tackle with this problem.

A: 

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

Graham Lee
+3  A: 

-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.

Vladimir
@Vladmir Yes it right. I got it. It should be checked NSInteger. Thanks a lot...
iSight
A: 

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).

Peter Hosey