I've an UITableViewController within an UITableView(named: AutocompleteTableView) that appears only when i'm editing a textfield in the UITableViewController.
I draw UITableView(AutoCompleteTableView) looking for the coordinates for the second section of my UITableViewController.
I'm scrolling the UITableViewController to the second section with :
self.tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: self.tableView.numberOfRowsInSection(1) - 1, inSection:
1), atScrollPosition: UITableViewScrollPosition.Top, animated: true)
After scrolled the UITableViewController I draw the coordinates for the UITableView(AutoCompleteTableView) with :
autocompleteTableView.frame = CGRectMake(0, self.tableView.rectForSection(1).maxY, self.view.frame.width, (self.tableView.contentSize.height - self.tableView.rectForSection(1).maxY))
So, when I started writing in the textfield, the AutocompleteTableView appears in the correct position, but when I deleted a row from this section, the AutoCompleteTableView never again appears while I start to writing in the TextField.
I'm calling the two funcs (Scroll, and Draw) in the
textfieldShouldChangeCaracter func.
Related
I'm trying to give a tableView and searchBar (tableView.tableHeaderView = searchBar) the same behavior as in the Messages and Mail apps i.e. hide the searchBar off the top of the parent view and scroll to show it.
The problem is the search bar is shown/hidden differently when the tableView has a different number of cells. How do I hide the search bar every time?
Not enough cells to fill the view
Just enough cells to fill the view
More than enough cells to fill the view
The method I'm using is tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)
When i add some text in TableView, it will show from Top of the tableview but i want to show it from bottom of tableView.
1. My TableView Screen
When i add user entered text in array and refresh tableView it will load from Top of TableView like below image.
but i want to add it from bottom like below image.
Can you guys help me, how can i achieve this?
Thanks
I am able to bind Data from bottom of TableView. All credit goes to Rajeshkumar R for helping me.
Step 1, apply a transform to the table view rotating it 180deg
tableView.transform = CGAffineTransformMakeRotation(-M_PI);
Step 2, rotate your raw cell 180deg in tableView:cellForRowAtIndexPath:
cell.transform = CGAffineTransformMakeRotation(M_PI);
Step 3, reverse your datasource. If you're using an NSMutableArray insert new objects at location 0 instead of using AddObject...
Now, the hard part is remembering that left is right and right is left only at the table level, so if you use
[tableView insertRowsAtIndexPaths:targetPath withRowAnimation:UITableViewRowAnimationLeft]
you can use the function below. It worked for me.
func scrollToLastRow() {
let indexPath = NSIndexPath(row: messageHistoryArray.count-1, section: 0)
self.createChatTableView.scrollToRow(at: indexPath as IndexPath, at: .bottom, animated: true)
}
I have a UITableView that displays custom cells. By pressing a button, the user can change the content of my UITableView
Scenario:
Load an array with 1000 elements
Scroll table to bottom (gives me about 20,000 contentOffset.y after scrolling)
On button pressed, I replace my array with 300 elements
Call reloadData in main thread (gcd)
After the step 4, what should be the correct new immediate contentOffset.y of my UITableView? I expected it to be 0 and my table scroll to top but for some reason it's not and does not scroll back to top. Is this the normal behavior of UITableView?
From Apple's docs... https://developer.apple.com/reference/uikit/uitableview/1614862-reloaddata
For efficiency, the table view redisplays only those rows that are
visible. It adjusts offsets if the table shrinks as a result of the
reload.
So, yes, it's normal to not scroll all the way to the top on reloadData.
If you want it to scroll to the top, either use setContentOffset or:
.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.top, animated: false)
Yes, It is normal behavior of UITableView. If you an want that table view should scrolled to top after reloading, you have to do that using below code.
let newOffset = CGPoint(x: currentOffset.x, y: 0)
tableView.setContentOffset(newOffset, animated: false)
Automatically, UITableView retain it's scroll offset while reloadData function called.
The first cell of my tableView inside my UITableViewController starts just a bit in/underneath my UINavigationController. How can I fix this? I already tried:
self.tableView.contentInset = UIEdgeInsetsMake(63, 0, 0, 0) inside my viewDidLoad and viewDidAppear both did help a bit but only after scrolling..
I have a UITableView that should show a particular row in its middle when it is first displayed. In viewDidLoad, I use scrollToRowAtIndexPath to achieve this:
// Center vertically on current row
let scrollIndexPath = NSIndexPath(forRow: currentRow, inSection: 0)
tableView.scrollToRowAtIndexPath(scrollIndexPath, atScrollPosition: UITableViewScrollPosition.Middle, animated: false)
This makes the top of the current row aligned with the middle of the table view meaning that the content of the row looks lower than it should be. How can I make the middle of the row align with the middle of the table view?
UITableView is a subclass of UIScrollView so you can use:
scrollRectToVisible:<#(CGRect)#> animated:<#(BOOL)#>
and calculate CGRect yourself, this way you have way more control than with using:
scrollToRowAtIndexPath