Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何以编程方式设置UITableView的高度_Ios_Swift_Uitableview_Tableview - Fatal编程技术网

Ios 如何以编程方式设置UITableView的高度

Ios 如何以编程方式设置UITableView的高度,ios,swift,uitableview,tableview,Ios,Swift,Uitableview,Tableview,我有一个表视图,我想通过编程的方式设置表视图的高度。我该怎么做 任何帮助都将不胜感激。 多谢各位 在视图中使用此代码显示: tableView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: desiredHeight) 这是Swift 3.1版本: //Create table view let tableView = UITableView(); //Set frame tableView.fram

我有一个表视图,我想通过编程的方式设置表视图的高度。我该怎么做

任何帮助都将不胜感激。
多谢各位

在视图中使用此代码显示:

tableView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: desiredHeight)

这是Swift 3.1版本:

//Create table view
let tableView = UITableView();
//Set frame
tableView.frame = CGRect(x: 0, y: 0, width: 100, height:100);
//Add the table to a view as a subview
superView.addSubview(tableView); 
//...

Sivajee Battina的回答在技术上是正确的,但是,在使用Swift 3时不应使用CGRectMake。下面是一个快速的答案:

tableView.frame = CGRect(x: 0, y: 0, width: myWidth, height: myHeight)

步骤1:制作UITableView的出口

步骤2:现在在ViewDidLoad()方法中设置tableView的框架

viewDidLoad()

试试这个代码

  tableView.frame = CGRect(x: 10, y: 10, width: yourwidth, height: yourheight)

您是否尝试过设置表框?此时,您是否真的在使用autolayout,因此您可能希望通过编程方式搜索、向UITableview添加约束这将不会在Swift 3中编译。更新了答案bro。谢谢;-)
tableView.backgroundColor = UIColor.black
tableView.frame = CGRect(x: 0, y: 0, width: 180, height: 400)
  tableView.frame = CGRect(x: 10, y: 10, width: yourwidth, height: yourheight)