到目前为止,我已经通过在第一个 View Controller 中使用 viewDidAppear 中的方法让登录 View 出现在应用程序的开头,但是一旦用户名和密码获得 Web 服务的批准,第一个 View Controller 出现一瞬间,然后立即返回登录 View 。
我是不是忘记了什么???我只在我的登录 View 和我的第一个 View 中进行编码。
第一次编码:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
[self dismissModalViewControllerAnimated:YES];
}
这是我的登录 View 中的编码
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSMutableString *Yes =[[NSMutableString alloc] initWithString:@"Y"];
if ([ capturedCharacters isEqualToString:Yes])
{
//[self presentModalViewController:vc animated:YES];
[self dismissModalViewControllerAnimated:YES];
}
else
{
// ask user to login again,
}
[capturedCharacters release];
capturedCharacters = nil;
if ([elementName isEqualToString:@"str_partinfo"]) {
// We are no longer in an item element
inItemElement = NO;
}
}
我正在使用标签栏模板
最佳答案
通过调用:
- (void)viewDidAppear:(BOOL)animated
每次您的父 View Controller 进入 View 时,您都会呈现登录 View 。我认为实际发生的情况是,当登录 View 被关闭时,“viewDidAppear”会触发,再次调用登录 View 。
尝试将逻辑放入 -(void)viewDidLoad 中,看看是否有效:
- (void)viewDidLoad
{
[super viewDidLoad];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
[self dismissModalViewControllerAnimated:YES];
}
或者,您可以有一个 BOOL 指针,伪代码:
BOOL loginSuccessful;
if(!loginSuccessful)
{
//ShowLogin
loginSuccessful = TRUE;
}
关于ios - 如何永久关闭我的登录 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9626282/