lundi 3 août 2015

Tableview size change when i touch the screen

I have got 2 TableViews in the ViewController(1: tableView 2: tableview2) - the size of each one in the MainStoryBoard is 40, BUT in the code the size of each one is by its content size (for example: if i got 4 rows and each row is 22 so the tableview is 88).

When I run the app I see the size of the Tableviews as I want - by its content size, but when I click the screen to scroll down (I also got ScrollView) both tableviews become smaller to the size of the MainStoryBoard, which is 40.

What can I do to do not make the tableview smaller when I click it? Here is my code so far:

override func viewDidAppear(animated: Bool) {
    tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.contentSize.height)
    tableview2.frame = CGRectMake(tableview2.frame.origin.x, tableview2.frame.origin.y, tableview2.frame.size.width, tableview2.contentSize.height)
}
override func viewDidLayoutSubviews(){
        if tableView == tableview2 {
        tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.contentSize.height)
        tableview2.frame = CGRectMake(tableview2.frame.origin.x, tableview2.frame.origin.y, tableview2.frame.size.width, tableview2.contentSize.height)
        tableView.reloadData()
        tableview2.reloadData()
        } else {
            tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.contentSize.height)
            tableview2.frame = CGRectMake(tableview2.frame.origin.x, tableview2.frame.origin.y, tableview2.frame.size.width, tableview2.contentSize.height)
            tableView.reloadData()
            tableview2.reloadData()
        }
    }

Aucun commentaire:

Enregistrer un commentaire