-4

Start tableview when starting the view from below.

I have a one-dimensional array for the header and a two-dimensional array for the cellen.

Is it possible to start the tableview when calling viewDidLoad () from below? So you have to scroll up.

many thanks

Code for my Header:

 override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView = Bundle.main.loadNibNamed("TableViewCell1", owner: self, options: nil)?.first as! TableViewCell1
    headerView.date.text = aHeaderDate[section]
    headerView.backgroundColor = UIColor.white
    return headerView
}

Code for my Cell:

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell2 = Bundle.main.loadNibNamed("TableViewCell2", owner: self, options: nil)?.last as! TableViewCell2

    let sectionTime = dimArrayTime[indexPath.section][indexPath.row]

    cell2.time.text = sectionTime
    return cell2

}

Example, so it is now: enter image description here

That's how it should be:

enter image description here

NewYorker
  • 67
  • 1
  • 8
  • Can you explain more what you want to do? Show what kind of array you have and share screenshot what you want to draw with your current available array. – Syed Qamar Abbas Feb 14 '18 at 18:21

3 Answers3

0

In my opinion, the easiest way to achieve that is to transform table view and its cells:

Mirror the table view:

tableView.transform = CGAffineTransform(scaleX: 1, y: -1)

In viewForHeaderInSection and cellForRowAt mirror those views as well:

headerView.transform = CGAffineTransform(scaleX: 1, y: -1)

cell.transform = CGAffineTransform(scaleX: 1, y: -1)
mag_zbc
  • 6,801
  • 14
  • 40
  • 62
  • that is a very good idea. But then my cell always appears over the header. – NewYorker Feb 15 '18 at 19:28
  • Thank you for your suggestion. I solved the problem by simply flipping my arrays with the array.reversed () function before displaying them in my tableview. – NewYorker May 17 '18 at 17:42
0

Can you please try following code

[tableView reloadData];
int lastRowNumber = [tableView numberOfRowsInSection:0] - 1;
NSIndexPath* ip = [NSIndexPath indexPathForRow:lastRowNumber inSection:0];
[tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:NO];
hitesh landge
  • 362
  • 4
  • 14
0

You can use following source code

dispatch_after(time, dispatch_get_main_queue(), {
  tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: model.dataArray.count - 1, inSection: 0), atScrollPosition: .Bottom, animated: true)
})
hitesh landge
  • 362
  • 4
  • 14