I have a UITableView and its data gets refreshed from a server connection. For the UITableViewcell, I have layout some labels across the row. So it can consider as a grid with UILabels(total no of labels = table rows * table columns).
When the data gets refreshed I have added an animation for the UILabel to highlight the table cell update.(Labels background color changes for about 0.5 seconds and restore to the previous background color). There I compare the old value with new value and I added the animation with comparing those. It works fine.
My problem is when I scroll the table, because of the reusable cells the labels are getting animated.(although the corresponding values are not change). Anyone have an idea to how to avoid this issue? thanks.
It sounds like you're calling reloadData and animating in tableView:cellForRowAtIndexPath:. Don't do this. There's no guarantee that UITableView will reuse the same cell (it sounds like it does, but it's unwise to rely on this, and I'm pretty sure it doesn't for reloadRowsAtIndexPath:withRowAnimation:). It will do the wrong thing if you remove a row, for example.
You can use -[UITableView visibleCells] to get an array of the currently visible cells. Loop over the array and use a custom method to tell each cell to reload with animation.
Related
Is it possible to have a UITable with cells that are all the same, each containing buttons that only effect that cell (based on indexPath.row I'm guessing), without having to make a custom cell?
I too need this, but I have a custom cell.
#kaylaGalway your method sounds like it could work for me, could you elaborate? As I have been searching for this answer for hours now (Swift 3)
You can design your table cells freely. It is possible to have a different cell for each and every row within the very same table.
When you have matching cell types for each row you can also add buttons (one or more) in these rows. They can also point to the very same function. With a clever usage of the 'tag' you can identify each individual button. Using the Indexpath.row you can naturally also identify the row in the table.
I have a UITableView. It loads sets of events at regular time intervals. I want to be able to scrol the table view to see all events. I had inserted latest events at position number zero in a row. So whenever I reload the data, my table view has moved one row down. So the user can't view exactly what he wants to read. So I want to reload the UITableView without moving its scrolling position. How can I do that?
Note that my event text height should be vary based on events.
You can either use UITableView's -scrollToRowAtIndexPath:atScrollPosition:animated: or, probably better, UIScrollView's -setContentOffset:animated:, to reposition the table view. You'll probably just have to note the current offset, calculate the new offset (based on where & how many rows you added), and set it after you update the table.
I have some options in an UITableView and want that the user can scroll forever. When the end is reached, I want to append the begginning so the user can continue to scroll.
How would I do that?
In tableView:numberOfRowsInSection: return some huge number, and act accordingly in tableView:cellForRowAtIndexPath: by returning same cells over and over.
You can also have limited number of rows, and at the end show a different cell - containing a button for user which he can use to append new rows. When that button is clicked you simply call [tableView reloadData] and provide more rows in table's data source.
Aren't you by any chance misusing the table-view for something it doesn't fit that well ? Maybe you would be better off using just a UIScrollView and reposition subviews as user scrolls over.
I think the only problem is how to trick in the method numberOfRows:. One possible solution is to return some big number here, for example, 10 000. Then, you set up a correct cellForRowAtIndexPath: to return based on your data's number modulo. For example, if you have 100 data entity, then you have to get the indexPath.row % 100
I need a way to alter the UITableView row height differently, but without implementing the delegate method -tableView:heightForRowAtIndexPath: because it causes me some serious performance problems in an indexed table with 15.000 rows.
Now the thing is, that every third table is 10 units bigger. than the others. These are a different kind of UITableViewCell subclass.
But I couldn't find a property in UITableViewCell that could help here. What could I do?
You cannot usefully set the cell's height from the cell class itself. The only options are that delegate method and setting rowHeight on the table view, which obviously applies the same height to all cells.
Looks like the docs acknowledge there are performance issues for that delegate when using more than 1000 cells or so.
Perhaps you can split you table in sections and set those larger cells as table section headers (you can specify a separate height for those). Then you will have to deal with the way section headers start to stack at the top of the table; I don't know for sure but you may be able to alter that behavior.
I an getting same value in my tableview after the 11 row.
after the 11th row again the name of row start as first row.
How unfortunate. Perhaps if you told us something about how you're populating the tableview, someone might be able to help you.
http://www.catb.org/~esr/faqs/smart-questions.html
In your table view data source you are probably calling dequeue to get a recycled UITableViewCell instance. If it returns nil, you are creating a new cell and putting the right data in it. If it returns a recycled cell, you are probably not updating it.
Move your updating code so that it is executed whether the cell is recycled or new.