NSTableView, [table selectedCell] suddenly gives nil value - objective-c

I must have changed something to break this line of code in my project:
[table selectedCell] //it gives nil value
but the table row is selected (it's highlighted).
Table is cell based.
What could be the reason?
UPDATE: I've just seen in the documentation that this method has been deprecated in 10.10. But then what should I use to get the current selected cell?

It really depends on what you are trying to do. -selectedCell isn't specific to NSTableView; it's inherited from NSControl and isn't particularly useful to a table view. Individual cells can't be "selected", but rows or columns can.
Cells can be edited, however. Is that what you're trying to find out? Which cell is currently being edited? If so, you can use -editedRow and -editedColumn.
Otherwise, you can get either the selected row / row indexes or the selected column / column indexes, but row and column selection are mutually exclusive and either would encompass multiple cells. Since NSControl's -selectedCell can only ever give you one cell, you'll never truly be able to get an answer that makes sense using that method on a table view. But of course only one cell can be edited at a time.
So is it selection or editing you're looking for?

Related

Is it possible to set vb.net datagridview cell alignment without modifying whole column?

I am trying to set the alignment of a specific cell in a row/column to be right aligned. However I do not want to set the whole row, or whole column to right aligned. Is it possible to set the cell only? From what I've seen online I'm starting to think it isn't possible.
You would need to hook up to the RowDataBound event. This fires as each row is databound. Check that the row is a data row (as opposed to a header or footer). Then check the value in the column you are interested in. If the value meets your criteria for right justification then apply that to the column in question.
Note if you are using AlternateItemTemplate then check both Item rows and AlternateItem rows.
I've used this method to say change the backround colour of values that fall outside a range.

How to prevent only one row to be ordered-obj c

I have a table view. And I have multiple rows. While doing the reorder in editing mode, I want one row to stay in the first index all the time. So, if a user wants to swap a row with the first row, it shouldnt allow it. But it should be possible between the second and the third row.
How can I do this?
Thank you very much in advance
Set the first table view cell's showsReorderControl to NO and return NO in tableView:canMoveRowAtIndexPath: for the first row.
You can also implement the UITableViewDelegate method tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:
Here you can return an alternate index path if the proposed one is (0, 0).
Return Value
An index-path object locating the desired row destination
for the move operation. Return proposedDestinationIndexPath if that
location is suitable.
Discussion
This method allows customization of the target row for a
particular row as it is being moved up and down a table view. As the
dragged row hovers over a another row, the destination row slides
downward to visually make room for the relocation; this is the
location identified by proposedDestinationIndexPath.

Use columns.add(...) in Word with non-uniform column widths?

Problem I'm having is that table.Columns.add(ref Object BeforeColumn) requires a reference to another column in the table. However, when I try to access the last column in the table to pass as a reference using table.Columns.Add(table.Columns[table.Columns.Count])
I get the error:
"Cannot access individual columns in this collection because the table has mixed cell widths."
As my current work around, I catch the error, and call table.Columns.DistributeWidth() to make sure the columns are uniform and run the rest of the code. However, I lose the formatting of my cell widths this way, which is unfortunate.
Is there any way I can workaround this without losing the cell width?
(I realize one way is to store every cell's width before running this process, and then re-applying the widths afterward, but this seems like a very costly solution to something that should be simpler)
I've found one way to do it. Here's how I approached it.
*Caution, I'm assuming that the table is uniform. i.e. The number of columns is the same across all the rows. (Note, the API has a Table.uniform function, but the description is not complete. In the API it says "True if all the rows in a table have the same number of columns." However, it also checks if the columns have uniform width).
Instead of using table.Columns.Add(table.Columns[table.Columns.Count]) to add a column before the last below, I select a cell in the table and used the insert command:
//assuming table is the name of the table you want to add columns to
table.Cell(1, table.Columns.Count).Select();
word.Selection selection = table.Application.ActiveWindow.Selection;
selection.InsertColumns();
This might actually be a better way to add columns, as the api gives you way more options on how to insert (i.e. use InsertColumnsRight to insert to the right of the column). The Columns.Add(...) function by default inserts to the left of the select

issue about UITableViewController?

I have a table view, and its first row has different style from the rest. After I scrolled the table once, some other rows' style also become that of the first row. What could be the problem?
Remember that your tableview cells are being reused. So a cell that has been configured for row 0 is then popping back up further down, with its configuration intact. So you've got two options here:
Completely reset the state of your cells when they're being reused
Return a cell with one reuse identifier for row 0 and another cell with a different reuse identifier for everything else
When this was mentioned at WWDC it seemed that the second option is preferable, I suspect because it means less messaging of label objects and the like as the table scrolls.

Grouped table with image in first row (and section), the remaining ones having text with different length

I have a grouped table with two sections where I display text with different length and therefore cell height.
I have solved the problem with the different length/height with constrainedToSize in cellForRowAtIndexPath.
Now I want to add a section with one single row in which I want to show a picture.
How should I best implement that? (still a bit of a beginner with the Objective C)
I would guess that I would have to create an UIImageView and somehow link that to the cell, but my biggest concern is how do I do with the dequeueReusableCellWithIdentifier now that I will have two different type of cells?
Appreciate any advice that will help me save time from trial and error!
I ended up doing this:
Since my image is in my first section (and nothing else in that section) I divided my cellForRowAtIndexPath in to two parts with a simple if statement. One for the first section and one for the rest. Then I use two different dequeueReusableCellWithIdentifier and can set up two kind of cells. So far it work fine.