Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.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 Swift:如何在登录视图后显示选项卡栏控制器_Ios_Xcode_Swift_Uitabbarcontroller - Fatal编程技术网

Ios Swift:如何在登录视图后显示选项卡栏控制器

Ios Swift:如何在登录视图后显示选项卡栏控制器,ios,xcode,swift,uitabbarcontroller,Ios,Xcode,Swift,Uitabbarcontroller,我在这里看到过许多类似的帖子,但它们都是关于Objective-C的,而我正在用Swift开发我的应用程序。从图中可以看到,我有一个登录屏幕视图,并且正确地实现了登录机制 现在我希望登录成功后,显示选项卡栏控制器。在我的登录视图控制器中,我有以下登录功能: var finalURL:NSString = "\(Settings.webServerLoginURL)?username=\(username)&password=\(password)" LoginServ

我在这里看到过许多类似的帖子,但它们都是关于Objective-C的,而我正在用Swift开发我的应用程序。从图中可以看到,我有一个登录屏幕视图,并且正确地实现了登录机制

现在我希望登录成功后,显示选项卡栏控制器。在我的登录视图控制器中,我有以下登录功能:

var finalURL:NSString = "\(Settings.webServerLoginURL)?username=\(username)&password=\(password)"

        LoginService.requestLoginWithURL(NSURL(string: finalURL as String)!, completionHandler: { (success) -> Void in
            if (success) {
                NSLog("Login OK")

                /* Scarica dal database i tasks di LoggedUser.id */
                /* Redirect al tab HOME dell'applicazione dove si mostrano il numero di task
                di quell'utente ed in cima "BENVENUTO: name surname" */


            }

            else {
                self.alertView.title = "Autenticazione fallita!"
                self.alertView.message = "Username o passowrd."
                self.alertView.delegate = self
                self.alertView.addButtonWithTitle("OK")
                self.alertView.show()
            }
所以我认为我应该在之后显示选项卡栏控制器

NSLog("Login OK")
但我不知道怎么做。我是Swift/XCode的初学者……如果你能解释一下的话。 感谢所有阅读过的人。

func settabbar可见(可见:Bool,动画:Bool){
func setTabBarVisible(visible:Bool, animated:Bool) {

//* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time

    // bail if the current state matches the desired state
    if (tabBarIsVisible() == visible) { return }

    // get a frame calculation ready
    let frame = self.tabBarController?.tabBar.frame
    let height = frame?.size.height
    let offsetY = (visible ? -height! : height)

    // zero duration means no animation
    let duration:NSTimeInterval = (animated ? 0.3 : 0.0)

    //  animate the tabBar
    if frame != nil {
        UIView.animateWithDuration(duration) {
            self.tabBarController?.tabBar.frame = CGRectOffset(frame!, 0, offsetY!)
            return
        }
    }
}

func tabBarIsVisible() ->Bool {
    return self.tabBarController?.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame)
}

// Call the function from tap gesture recognizer added to your view (or button)

@IBAction func tapped(sender: AnyObject) {
    setTabBarVisible(!tabBarIsVisible(), animated: true)
}
//*无法在viewDidLayoutSubviews()之前调用此函数,因为在此时间之前未设置帧 //如果当前状态与所需状态相匹配,则进行保释 如果(tabBarIsVisible()==可见){return} //准备好框架计算 设frame=self.tabBar控制器?.tabBar.frame 让高度=框架?.size.height let offsetY=(可见?-height!:height) //零持续时间意味着没有动画 let duration:NSTimeInterval=(动画?0.3:0.0) //设置选项卡栏的动画 如果帧!=nil{ UIView.animateWithDuration(持续时间){ self.tabBar控制器?.tabBar.frame=CGRectOffset(frame!、0、offsetY!) 返回 } } } func tabBarIsVisible()->Bool{ 返回self.tabBar控制器?.tabBar.frame.origin.y
要从登录页面显示tab bar控制器,请将登录页面和tab bar控制器与显示序列连接,并在属性检查器中为其指定一个标识符(如“mySegueIdentifier”)

要添加segue,只需右键单击并从登录视图控制器拖动到TabbarController

在成功登录中,您只需调用“performsguewithidentifier”方法,如下所示

self.performSegue(withIdentifier: "mySegueIdentifier", sender: nil)
在你的情况下,你在这一行之后叫它

NSLog("Login OK")
如果您不想从登录页面导航到TabbarController,也可以在成功登录后将其设置为rootViewController。 为此,请将标识符设置为TabbarController(例如“myTabbarController”)

编辑:

斯威夫特3

 let appDelegate = UIApplication.shared.delegate! as! AppDelegate
    
 let initialViewController = self.storyboard!.instantiateViewController(withIdentifier: "myTabbarControllerID") 
 appDelegate.window?.rootViewController = initialViewController
 appDelegate.window?.makeKeyAndVisible()

快乐编码…)

我在尝试从用于touchID的控制器切换到TabBarController时遇到了相同的问题。通过在异步块中创建segue,我解决了这个问题

dispatch_async(dispatch_get_main_queue(), {
    self.dismissViewControllerAnimated(false, completion: {})
    self.performSegueWithIdentifier("authnToAppSegue", sender: nil)
})

为选项卡栏控制器提供故事板ID(如“选项卡栏”),并像普通UIViewController一样推送它:

let nextViewController = self.storyboard?.instantiateViewController(withIdentifier: "tabbar") as! UIViewController

self.navigationController?.pushViewController(nextViewController, animated: true)

通过以下代码从任何控制器调用Tabbarcontroller,默认选择第一项

    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

    let nextViewController = storyBoard.instantiateViewController(withIdentifier: "HomeTabBar") as! UITabBarController

    self.navigationController?.pushViewController(nextViewController, animated: true)

谢谢你的回答。恐怕我不明白。。。我添加了这些函数,并在登录成功后调用了setTabBarVisible(!tabBarIsVisible(),animated:true),但什么也没发生。。。可能是因为故事板中的登录视图控制器和选项卡栏控制器之间没有链接?制作一个导航控制器并将视图堆叠在其中。。。视图不是导航项的所有者,但导航控制器是…这里有一个很好的教程,介绍如何执行此操作,谢谢。我会看看那个教程…我真的不知道从哪里开始开发这个应用程序…你需要了解导航控制器和视图控制器之间的区别和联系,因为导航控制器是工具栏(顶部栏)和选项卡栏(底部栏)的所有者因此,如果你想在应用程序中使用它们,你需要使用导航控制器制作堆栈,然后在其中放置其他视图控制器(导航控制器是一个堆栈,在该堆栈上可以推送和弹出视图控制器)。谢谢你,这真的很有启发性和简单。它起作用了。还有一件事:当视图切换到选项卡栏控制器时,我只看到第一个选项卡图标和标题(主页)已启用。我也想看到其他标签,因为没有启用,但这只发生在我点击“他们”(在空白空间,他们应该是……)这是固定的吗?这是默认的标签栏行为。基于此,只有用户才能知道他在哪个页面。你可以在很多应用程序中观察到这一点。等等,也许我没有很好地解释这些事情……事实是其他图标根本没有出现。例如,如果我在“主页”选项卡中,我只看到主页图标,而其他图标不显示,因此用户不知道在哪里点击。。。对吗?您可能忘了将图像放入“selectedImage”属性-->tabBarItem.selectedImage=UIImage(名为:“tab active.png”)?的选项卡栏项目中。imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)。我编辑了答案。检查一下。在您的情况下,您必须给出登录视图控制器和选项卡栏控制器之间的顺序。不在登录按钮和选项卡栏控制器之间。这里是另一种方法-
    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

    let nextViewController = storyBoard.instantiateViewController(withIdentifier: "HomeTabBar") as! UITabBarController

    self.navigationController?.pushViewController(nextViewController, animated: true)