如何设置元素的宽度等于窗口的宽度?(How to set an element's width equal to window's width?)
使用:
$(my_div).width(window.innerWidth)
没有提供所需的结果,因为它没有考虑垂直滚动条,因此元素溢出窗口,创建一个水平滚动条,如下图所示。
插图http://dl.dropboxusercontent.com/u/62862049/Screenshots/om.png
Using:
$(my_div).width(window.innerWidth)
Does not provide the desired result, because it does not account for the vertical scrollbar, so the element overflows the window, creating a horizontal scrollbar, as illustred below.
Illustration http://dl.dropboxusercontent.com/u/62862049/Screenshots/om.png
原文:https://stackoverflow.com/questions/16986941
最满意答案
在你的appDelegate.m里面你的didFinishLaunchingWithOptions
//authenticatedUser: check from NSUserDefaults User credential if its present then set your navigation flow accordingly if (authenticatedUser) { self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController]; } else { UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"]; UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController]; self.window.rootViewController = navigation; }
在SignUpViewController.m文件中
- (IBAction)actionSignup:(id)sender { AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate]; appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController]; }
在文件MyTabThreeViewController.m
- (IBAction)actionLogout:(id)sender { // Delete User credential from NSUserDefaults and other data related to user AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate]; UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"]; UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController]; appDelegateTemp.window.rootViewController = navigation; }
Here is what I ended up doing to accomplish everything. The only thing you need to consider in addition to this is (a) the login process and (b) where you are storing your app data (in this case, I used a singleton).
As you can see, the root view controller is my Main Tab Controller. I did this because after the user has logged in, I want the app to launch directly to the first tab. (This avoids any "flicker" where the login view shows temporarily.)
AppDelegate.m
In this file, I check whether the user is already logged in. If not, I push the login view controller. I also handle the logout process, where I clear data and show the login view.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Show login view if not logged in already if(![AppData isLoggedIn]) { [self showLoginScreen:NO]; } return YES; } -(void) showLoginScreen:(BOOL)animated { // Get login screen from storyboard and present it UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; LoginViewController *viewController = (LoginViewController *)[storyboard instantiateViewControllerWithIdentifier:@"loginScreen"]; [self.window makeKeyAndVisible]; [self.window.rootViewController presentViewController:viewController animated:animated completion:nil]; } -(void) logout { // Remove data from singleton (where all my app data is stored) [AppData clearData]; // Reset view controller (this will quickly clear all the views) UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; MainTabControllerViewController *viewController = (MainTabControllerViewController *)[storyboard instantiateViewControllerWithIdentifier:@"mainView"]; [self.window setRootViewController:viewController]; // Show login screen [self showLoginScreen:NO]; }
LoginViewController.m
Here, if the login is successful, I simply dismiss the view and send a notification.
-(void) loginWasSuccessful { // Send notification [[NSNotificationCenter defaultCenter] postNotificationName:@"loginSuccessful" object:self]; // Dismiss login screen [self dismissViewControllerAnimated:YES completion:nil]; }
相关问答
更多-
首先,您应该注意,根据Apples开发人员的说明,您不应该继承UINavigationController的子类。 其次,这是基于意见的,但我建议您应该使用您的应用程序委托类作为检查登录状态的支柱点,它是UINavigationController的单例,实际上是。 OK so here is what I ended up doing: As pointed out by John Woods, don't subclass UINavigationController. Instead, I creat ...
-
故事板登录屏幕的最佳做法,在注销时处理数据清除(Best practices for Storyboard login screen, handling clearing of data upon logout)[2022-04-06]
在你的appDelegate.m里面你的didFinishLaunchingWithOptions //authenticatedUser: check from NSUserDefaults User credential if its present then set your navigation flow accordingly if (authenticatedUser) { self.window.rootViewController = [[UIStoryboard storybo ... -
将loginVC作为根视图控制器,如下所示: let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC") as! LoginVC let appDel:AppDelegate = UIApplication.shared.delegate as! AppDelegate appDel.window?.rootViewController = loginVC Make loginVC as root ...
-
使用Parse 。 这真的很简单...... Parse是一个适用于iOS的SDK,它允许您执行各种操作,并使用其非常棒的免费实现包来完成用户帐户的管理。 Parse SDK附带一个完全可自定义的登录和注册控制器,可与您的应用程序的在线用户数据库链接。 他们有精彩的教程,你可以在这里查看他们的文档。 编辑: 在请求之后,这里是一个类似SO问题的链接,其中有一个更以登录为中心的答案: 如何制作像Facebook应用程序一样的登录屏幕? I ended up with Building a View Contr ...
-
正如文件所说 如果使用cookie来传播会话ID(默认行为),则必须删除会话cookie。 setcookie()可能会用于此。 if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params[ ...
-
感谢Brad Dwyer提供的调试信息,我们将问题范围缩小到Facebook模块和iOS 6帐户框架之间的交互。 我们的v1.4.46平台版本修复了该问题 Thanks to debug information provided by Brad Dwyer we narrowed down the issue to the interaction between the Facebook module and the iOS 6 accounts framework. The problem is fixe ...
-
使用Storyboard登录屏幕(Login Screen using Storyboard)[2022-07-29]
If(Login Successful){ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil]; HomeViewController* viewController = [storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]; [self presentV ... -
使用web.py登录和注销(Login and logout with web.py)[2022-03-05]
这里的问题是,如果他们使用GET方法访问页面,则不会检查他们是否已登录。 您需要进行如下更改: def GET(self): if session.logged_in: last_login = web.cookies().get('time') if last_login == None: last_login_data = u'ZalogowaĹ‚eĹ› siÄ™ pierwszy raz.' else: ... -
我在我们的应用程序中实现了这一点。 在此,我们会在添加新商家信息时将通知发送给用户。 用户可以同时从多个设备登录。 设备可能是android或ios任何东西。 此外,多个用户可以从同一设备登录(登出以前的用户后)。 用户从Android设备登录时,将从GCM获取注册ID。 对于一个设备,此GCM ID不是常量,只要您再次从GCM服务器请求它,它就会更改。 我们使用通知密钥将通知发送到多个设备,它包含所有设备的GCM寄存器ID。 如果您丢失了通知密钥,则无法将其恢复。 更糟糕的是,您无法使用以前使用的通知密钥 ...
-
用户再次登录后,您希望应用程序在哪里? 假设您希望应用程序位于设置按钮所在的视图控制器(它从故事板中看起来如此)。 那个vc(导航控制器中的根vc)可以这样做: - (void)viewDidAppear:(BOOL)animated { if (/*login is needed*/) { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; ...