Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.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 如果TableView中有HeaderView,则Swift PrefersTargetItles不工作_Ios_Swift_Uitableview_Swift5 - Fatal编程技术网

Ios 如果TableView中有HeaderView,则Swift PrefersTargetItles不工作

Ios 如果TableView中有HeaderView,则Swift PrefersTargetItles不工作,ios,swift,uitableview,swift5,Ios,Swift,Uitableview,Swift5,我将一个TableViewController替换为一个简单的ViewController(当然还有一个TableView) 我有一个很奇怪的问题: 如果TableView中没有视图:✅ 它起作用了 如果有视图:❌ 默认情况下,标题不是大的,我必须滚动以大模式显示它。(有趣的是,视图并没有固定在顶部,正如您在屏幕截图中看到的那样) 当我到达视图控制器时: 滚动后: 这是我的代码: class TestViewController: UIViewController { @IBOut

我将一个
TableViewController
替换为一个简单的
ViewController
(当然还有一个
TableView

我有一个很奇怪的问题:

  • 如果TableView中没有视图:✅ 它起作用了

  • 如果有视图:❌ 默认情况下,标题不是大的,我必须滚动以大模式显示它。(有趣的是,视图并没有固定在顶部,正如您在屏幕截图中看到的那样)

当我到达
视图控制器时

滚动后:

这是我的代码:

class TestViewController: UIViewController {
   @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

      if #available(iOS 11.0, *) {
         self.navigationController?.navigationBar.prefersLargeTitles = true
      }
    }
}

extension TestViewController: UITableViewDataSource, UITableViewDelegate {
   func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
      0
   }

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

}
你需要设置

navigationController.navigationBar.prefersLargeTitles=true
在按下
TestViewController
之前

我在操场上跑步时工作:

导入UIKit
导入PlaygroundSupport
最终类TestViewController:UIViewController{
重写func loadView(){
super.loadView()
让tableView=UITableView(帧:.0,样式:.plain)
视图=表格视图
title=“大标题”
view.backgroundColor=.white
tableView.dataSource=self
tableView.delegate=self
}
}
扩展TestViewController:UITableViewDataSource、UITableViewDelegate{
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回0
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
返回UITableViewCell()
}
}
//在实时视图窗口中显示视图控制器
让navigationController=UINavigationController(rootViewController:UIViewController())
navigationController.pushViewController(TestViewController(),动画:true)
//在按下viewController之前,请将PreferSlargetTitles设置为true!
navigationController.navigationBar.prefersLargeTitles=true
PlaygroundPage.current.liveView=navigationController

您可以通过在情节提要中设置
preferLarGetTitle
而不是通过编码来解决此问题

在故事板中选择NavigationController的NavigationBar(非NavigationItem)。
在属性检查器中,确保启用了“首选大标题”。

该方法不会改变任何内容。@KevinB,查看我的编辑。您可以在Xcode单视图游乐场中运行它。还是没用?我错过什么了吗?请说得更准确些。干杯我在tableView中添加视图(作为标题)时遇到问题如何将标题添加到tableView?看校长专区吗?嗨,凯文。我已经编辑了您的一些问题,因为我注意到您正在使用引号块(
)作为通用高亮显示。这不是它的目的-它有一个特定的语义含义,即它界定了引用,即某人或某事(在演讲、手册、书籍、杂志、报纸、博客、网络论坛等)所说的话。