swift 简单学习之简单框架

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        self.window!.makeKeyAndVisible()
        let tabVc = ZHZViewController()
        self.window!.rootViewController = tabVc;
        
        
        return true
    }

在appdelegate中注意设置标签栏时          self.window!.rootViewController = tabVc;系统会默认?   把他换成!就可以了


class ZHZViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let oneVc = ZHZOneViewController()
        seupViewController(oneVc, title: "首页")
        
        let twoVC = ZHZTwoViewController()
        seupViewController(twoVC, title: "食物")
        
        let threeVc = ZHZThreeViewController()
         seupViewController(threeVc, title: "发现")
        
         let fourVc = ZHZFourViewController()
          seupViewController(fourVc, title: "设置")
     }
     func seupViewController(vc:UIViewController,title:String){
         vc.title = title
        let thnav = ZHZNavViewController(rootViewController: vc)
        thnav.tabBarItem.title = title
         addChildViewController(thnav)
     }

这里面因为简单设置暂时没有什么坑

关于系统联想的问题就是尽量不要把两个括号一起打出来 否则联想会出问题 就打印一个就行了!!!

class ZHZNavViewController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
     }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0{
            viewController.hidesBottomBarWhenPushed = true
          }
        super.pushViewController(viewController, animated: animated)
        
    }

push推出的时候一定要重写 pushViewController:这个方法,在联想的时候一定要看清楚viewController这个首字母是小写 如果联想大写的话后面的那个方法是出不来的额  这个坑已经掉好多次了  而且不用遵守代理方法  如果遵守的话只需要在后面加上,UInavigationControllerDelegate就行了,


        super.pushViewController(viewController, animated: animated)这个方法一定执行  否则黑屏,为什么的话上网搜(好像swift语法比较严谨)@!!!鄙人菜鸟一枚




你可能感兴趣的:(iOS之swift)