ios - 为什么从标签栏 Controller 推送时我的 View Controller 是黑色的?

标签 ios swift

我正在尝试从我的选项卡栏 Controller 推送到 View Controller 。请记住,这一切都不是在 Storyboard上完成的——它是严格程序化的。每次我按下 Controller 时,导航栏都会显示后退按钮,但 View 完全是黑色的:

let controller = NewsFeedDetailViewController()
navigationController?.pushViewController(controller, animated: true)

我不太清楚为什么会这样。有什么想法吗?

最佳答案

当以编程方式pushViewController 时,如果您没有设置目标 Controller 的backgroundColor,默认情况下它是黑色的(无背景色)。尝试给出这样的颜色:

class NewsFeedDetailViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .red
    }
}

关于ios - 为什么从标签栏 Controller 推送时我的 View Controller 是黑色的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54724431/

相关文章:

android - iOS上的教程信息气泡控件

ios - 我应该使用 UITableView 节标题还是静态 UITableViewCell?

iphone - 关闭 iOS 上下文菜单

ios - 更新到 Xcode 11 后,Xamarin iOS 应用程序在 iPad 上显示白色空白屏幕

arrays - for 循环中 addChild 的时间延迟导致错误! swift

objective-c - 如何将 Objective-C 指针数组转换为 Swift?

swift - 如何继续使图像在 ScrollView 特定区域内滚动?

iOS UITableView 在代码中移动单元格

ios - 检测两个物体之间是否发生碰撞

ios - 多个 MKPointAnnotations 上的自定义图像