Kuldeep
Kuldeep

Reputation: 4552

Add New data from Bottom in TableView

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

enter image description here

When i add user entered text in array and refresh tableView it will load from Top of TableView like below image.

enter image description here

but i want to add it from bottom like below image.

enter image description here

Can you guys help me, how can i achieve this?

Thanks

Upvotes: 2

Views: 1355

Answers (2)

Kuldeep
Kuldeep

Reputation: 4552

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]

Upvotes: 3

Stephanie
Stephanie

Reputation: 121

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)
}

Upvotes: 0

Related Questions