在界面构建器中调整主视图的大小

时间:2015-11-12 06:28:04

标签: ios xcode swift

我尝试按照教程进行操作,但这是一个非常古老的教程,当您使用应用程序视图运行应用程序时会遇到一些问题。

enter image description here

没有图像,我重建约束但没有任何改变。

ViewController的代码:

class MasterViewController: UIViewController {

  @IBOutlet var tableView: UITableView!
  @IBOutlet var searchBar: UISearchBar!

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showDetail" {
    }
  }

  override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    if let selectedIndexPath = self.tableView.indexPathForSelectedRow {
      self.tableView.deselectRowAtIndexPath(selectedIndexPath, animated: true)
    }
  }
}

extension MasterViewController: UITableViewDataSource, UITableViewDelegate {

  func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
  }

  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 0
  }

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
    return cell
  }

  func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
  }

  func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
  }

}

extension MasterViewController: UISearchBarDelegate {

  func searchBarSearchButtonClicked(searchBar: UISearchBar) {
  }

}

我如何调整它不仅适用于iPhone 4(或摆脱黑色区域)?

2 个答案:

答案 0 :(得分:2)

Images.xcassets>中添加适当的启动图像。适用于您要支持的分辨率的LaunchImage 。例如,对于iPhone 5肖像,分辨率为640x1136。

以下是Xcode中要查找的界面的屏幕截图:

enter image description here

答案 1 :(得分:0)

要解决此问题,请按照以下步骤操作:

  1. 导航至项目设置

  2. 在“应用图标和启动图像”下,点击“使用资产目录”

  3. 在显示的弹出窗口中选择“迁移”。

  4. 这应解决问题。