我有一个带有signin viewController的应用程序,它以模态方式呈现包含多个选项卡的tabBarController。每个选项卡都有一个navigationController和一堆视图。其中一个选项卡用于设置并具有注销按钮。
当用户按下注销按钮时,我想解除所有选项卡和tabBarController的所有导航堆栈,并返回初始登录viewController。基本上我想将应用程序恢复到初始状态。想知道实现这一目标的最佳做法是什么。
感谢
答案 0 :(得分:3)
如果要重置所有选项卡并在注销后将应用程序恢复到初始状态,您只需重置UITabBarController的 viewControllers 属性即可。
因此,如果您是UITabBarController的子类,则以下代码应将您的应用程序恢复到其原始状态。
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
?>
<?php
$json = file_get_contents('http://api.formice.com/mouse/stats.json?n= <?php echo $userRow['mouse']; ?> &l=en');
$obj = json_decode($json);
?>
<?php
$json = file_get_contents('https://api801.herokuapp.com/get/mice/<?php echo $userRow['mouse']; ?> ');
$objj = json_decode($json);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php echo $obj->name; ?> | CheeseStatz</title>
<link rel="shortcut icon" href="Favicon.ico" />
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
<link rel="stylesheet" href="../../bootstrap/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="../../dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet" href="../../dist/css/skins/_all-skins.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<!-- ADD THE CLASS layout-top-nav TO REMOVE THE SIDEBAR. -->
<body class="hold-transition skin-blue layout-top-nav">
<div class="wrapper">
<header class="main-header">
<nav class="navbar navbar-static-top">
<div class="container">
<div class="navbar-header">
<a href="index.php" class="navbar-brand"><b>Cheese</b>Statz</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
<i class="fa fa-bars"></i>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse pull-left" id="navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="index.php">Home <span class="sr-only">(current)</span></a></li>
<li><a href="http://www.transformice.com/">Transformice</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Stats<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="mice.php">Mice Stats</a></li>
<li><a href="race.php">Racing Stats</a></li>
<li><a href="boot.php">Bootcamp Stats</a></li>
<li><a href="surv.php">Survivor Stats</a></li>
<li class="divider"></li>
<li><a href="run4.php">Run for Cheese Stats</a></li>
<li class="divider"></li>
<li><a href="tribe.php">Your tribe Stats</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" id="navbar-search-input" placeholder="Search">
</div>
</form>
</div>
<!-- /.navbar-collapse -->
<!-- Navbar Right Menu -->
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- Messages: style can be found in dropdown.less-->
<li class="dropdown messages-menu">
<!-- User Account Menu -->
<li class="dropdown user user-menu">
<!-- Menu Toggle Button -->
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<!-- The user image in the navbar-->
<img src="http://outil.derpolino.shost.ca/avatar/avatar.php?p=cheesezwheel" class="user-image" alt="User Image">
<!-- hidden-xs hides the username on small devices so only the image appears. -->
<span class="hidden-xs"> <?php echo $obj->name; ?> </span>
</a>
<ul class="dropdown-menu">
<!-- The user image in the menu -->
<li class="user-header">
<img src="http://outil.derpolino.shost.ca/avatar/avatar.php?p=cheesezwheel" class="img-circle" alt="User Image">
<p>
<?php echo $obj->name; ?> - <?php echo $obj->title; ?>
<small>Level: <?php echo $objj->level; ?> </small>
</p>
</li>
<!-- Menu Body -->
<li class="user-body">
<div class="row">
<div class="col-xs-4 text-center">
<a href="blog.php">Blog</a>
</div>
<div class="col-xs-4 text-center">
<a href="help.php">Help</a>
</div>
<div class="col-xs-4 text-center">
<a href="log.php">Log</a>
</div>
</div>
<!-- /.row -->
</li>
<!-- Menu Footer-->
<li class="user-footer">
<div class="pull-left">
<a href="forum.php" class="btn btn-default btn-flat">Forum</a>
</div>
<div class="pull-right">
<a href="#" class="btn btn-default btn-flat">Sign out</a>
</div>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-custom-menu -->
</div>
<!-- /.container-fluid -->
</nav>
</header>
<!-- Full Width Column -->
<div class="content-wrapper">
<div class="container">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
CheeseStatz
<small>Transformice Api v.1.0.0</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="#"><?php echo $obj->name; ?></a></li>
<li class="active">Welcome</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="callout callout-info">
<h4>Welcome <?php echo $obj->name; ?>!</h4>
<p></p>
<!-- /.box-body -->
</div>
<!-- /.box -->
</section>
<!-- /.content -->
</div>
<!-- /.container -->
</div>
<!-- /.content-wrapper -->
<footer class="main-footer">
<div class="container">
<div class="pull-right hidden-xs">
<b>Version</b> 1.0.0
</div>
<strong>Copyright © 2015 <a href="http://transformice.com">Cheesezwheel</a>.</strong> All rights
reserved.
</div>
<!-- /.container -->
</footer>
</div>
<!-- ./wrapper -->
<!-- jQuery 2.1.4 -->
<script src="../../plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="../../bootstrap/js/bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="../../plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../../plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/app.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
</body>
</html>
来自文档:
如果在运行时更改此属性的值,则选项卡栏控制器会在安装新视图控制器之前删除所有旧视图控制器。新视图控制器的标签栏项目会立即显示,并且不会动画到位。
答案 1 :(得分:2)
这是我目前在应用程序中使用的代码,用于在&#34;登录&#34;之间移动。和#34;主要用户界面&#34;
let toViewController = // Login view controller here
let fromView = UIApplication.sharedApplication().keyWindow!.rootViewController!.view
UIApplication.sharedApplication().keyWindow?.rootViewController = toViewController
let toView = toViewController.view
toView.addSubview(fromView)
UIView.animateWithDuration(0.38, delay: 0.2, options: [], animations: {
fromView?.transform = CGAffineTransformMakeTranslation(-UIScreen.mainScreen().bounds.width, 0)
}) { finished in
fromView.removeFromSuperview()
}
答案 2 :(得分:0)
iOS 11-Swift 4
以对我来说非常有用的jstn答案为基础。我只映射了VC,以将其嵌入导航控制器中。
let rootViewController = UIApplication.shared.keyWindow?.rootViewController
guard let tabController = rootViewController as? TabController {
return
}
//create all your vcs here
// ...
// ...
let vcs = [vc1, vc2, vc3, vc4]
tabController.viewControllers = vcs.map {UINavigationController(rootViewController: $0)}
// Do additional clean up here (i.e. clean cache, UserDefaults, userData objects etc.)