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.
Related
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?
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.
I have a NSTableView in I want the the first row to be fixed.
I do not want the first row to be sorted while clicking on the header of any table column. The row should also be fixed while scrolling.
I think there are two ways to go:
Add a proprety to the objects in the tableview. For instance a boolean named 'isFirstRow'. Set this object to YES for the row you want first and add a sortDescriptor based on this property.
(I think this is the most clean solution).
Or remove the row from the tableArray, build the table and add this row back on the first position.
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.
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.