首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >求助一个手机Xcode助手教程里UITabBarControllerProject的问题?

求助一个手机Xcode助手教程里UITabBarControllerProject的问题?

提问于 2020-06-28 17:39:30
回答 1关注 0查看 311

按照课程要求,代码已经全部写好,但是在模拟器运行时,发现是一片白的。

主要涉及AppDelegate 和ViewController的问题,但是我还是没明白。

另外也尝试修改main.storyboard中的Class,但是没有实际的作用。

所写代码已打包完成。另附具体代码如下:

本人小白,如若表述不清,课程视频可以参考公众号“91年女神”中Xcode→UITabBarController视图控制器。

FirstSubViewController.swift

代码语言:js
复制
import UIKit

class FirstSubViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "Item #1"
        self.tabBarItem.image = UIImage(named: "home")
        self.tabBarItem.selectedImage = UIImage(named: "home")
        self.view.backgroundColor = UIColor.red

        // Do any additional setup after loading the view.
    }
    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
}

SecondSubViewController.Swift

代码语言:js
复制
import UIKit

class SecondSubViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "Item #2"
        self.tabBarItem.image = UIImage(named: "settings")
        self.view.backgroundColor = UIColor.purple
        // Do any additional setup after loading the view.
    }
    override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
        self.tabBarItem.badgeValue = "8"
        
    }
    
    override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */


}

AppDelegate.Swift

代码语言:js
复制
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        let viewController1 = FirstSubViewController()
        let viewController2 = SecondSubViewController()
        
        let tabViewController = UITabBarController()
        tabViewController.viewControllers = [viewController1, viewController2]
        tabViewController.selectedIndex = 0
        tabViewController.view.backgroundColor = UIColor.red
        self.window?.rootViewController = tabViewController
        
        let tabBar = tabViewController.tabBar
        let item = tabBar.items![0]
        item.image = UIImage(named: "home")
        item.title = "home"
        
        let item2 = tabBar.items![1]
        item2.image = UIImage(named: "settings")
        item2.title = "settings"
        item2.badgeValue = "9"
        return true
    }
   
    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }


}


回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档