I have rotated my table view by 90°. Now I want to get indexpath of middle cell. When table view is not scrolling, it is showing 3 cells. What I want is, when table view stops scrolling, it should middle cell of green color. Sometimes I get wrong indexpath when more then 3 cells are visible while fast scrolling.
I have attached image for reference
try this
NSIndexPath *middleIndexPath = [tableView indexPathForRowAtPoint:CGPointMake(tableView.center.y, tableView.center.x)];
UITableViewCell *middleCell = [tableView cellForRowAtIndexPath:middleIndexPath];
You can get contentOffset of table view. With contentOffset, you can calculate current row (contentOffset.y / row height)
Related
I have tableview with these tableview cells:
- cell have some collectionview and cell have Height larger than haft of screen
- cell have other tableview inside it
When access to the last item inside cell (collection cell or tableview cell inside), i swipe right to focus on next cell. But it not jump to next cell in tableview, It jump to other item on screen
Example: i have main tableview, in this table have some cell is expanded cell which have other small tableview inside it. When this cell was expanded and i swipe right to last item of small tableview, then i swipe right again to move to next cell of main tableview view. But this time the next cell of main tableview was not focused, but some other item in screen gets focus
Could you give me the hit! Thanks a lot.
The user will click a button in one of the cell and the table will reload the data.
I would like to let the user stay in the same position after the reload.
My table contain many section and each section has two row.
Each of them may have different height.
I have tried some of the methods provided by others but its doesn't work.
CGPoint offset = tableView.contentOffset;
[tableView reloadData];
[tableView setContentOffset:offset];
Is it related to my table that each row in each section has different heigt?
I have also check that the offset is correct after the table is reloaded.
But the appearance is wrong.
I found that the view of the table is not change after the setting the offset
In a tableview one cell overlaps the cell displayed under it when initially presented. When you scroll down until the top cell is not longer visible and then scroll back up the cell are ok again.
I deactivated the separators with this line:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
The second cell has a view that fill it from top to bottom, that was a border radius. When the cells are initially presented the border is covert.
How can i fix the spacing of the tableviewCells when they are initially loaded? Can i set the z index the second cell, so that the second cell is above the first one?
I finally found that the constraint of the the top cells where causing the trouble. I found a workaround by storing the layout constraint in a property and adjusting the constant of the constraint as needed.
For "Can i set the z index the second cell, so that the second cell is above the first one?"
UITableViewCell is subclass of UIView so in table view delegate use this :
secondCell.layer.zPosition = 1;
I'm looking to expand the height of the top cell in my collectionview with animation. The problem is when I detect a tap on the cell, I try animating the height and set the new height in the delegate: - collectionView:layout:sizeForItemAtIndexPath:indexPath. The issue I see an instant refresh after invalidating my collection flow layout and the animation happens afterwords. The effect I want is for the top cell to animate the expansion to the new height and push the rows beneath it along with the animation.
I'm only using one section with multiple rows. Should I try to use two sections and put the top cell in the first section and the remaining in the second section? Could I then animate the second section along with the height of the first section?
You need to do this three steps:
1.Invalidate your collectionViewLayout
self.collectionView.collectionViewLayout.invalidateLayout()
2.Reload desired indexPath or all the data inside a performBatchUpdates block
collectionView.performBatchUpdates({
self.collectionView.reload(at: DESIRED_INDEXPATH)
}, completion: nil)
3.Return the new height calculated in sizeForItemAtIndexpath delegate method
I have a UITableView of cells where one cell contains a UITableView. Selecting that row that contains the table pushes a new view onto the screen with a list of items. The user selects a list of items and then presses 'back' to pop that view. The parent view looks at the number of items selected and the height of the cell is supposed to adjust to show all items selected.
What happens is that when the view is reshown, the listed items extends into the cell below. If I scroll that cell off the screen, then back to it, the cell is then the right height showing all items correctly.
I've tried several things such as putting code into viewWillAppear of the main table like [self.view setNeedsDisplay] and [self.view setNeedsLayout], but it doesn't work.
I can't seem to find a way to make that cell redraw to it's right size without scrolling the table once the view appears.
Is there some other method to force the redraw before it actually appears?
try:
NSIndexPath *theIndexPath = [NSIndexPath indexPathForRow:cellRow inSection:cellSection];
NSArray *theIndexPaths = [NSArray arrayWithObject:theIndexPath];
[table reloadRowsAtIndexPaths:theIndexPaths withRowAnimation:NO];
What are you currently using to redraw the cell? Just waiting for it to redraw itself when it goes off screen and back on? Or are you using something like [table reloadData];?