我在我的 Storyboard中创建了一个现在的模态序列,如下图所示。
我的第一个场景有一个带有 Action 的按钮:
- (IBAction)loginButtonPressedid)sender {
[self Login];
}
进入这个方法:
- (void)Login
{
NSString *rawString = [self.idTextField text];
NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
[self.idTextField setText:[rawString stringByTrimmingCharactersInSet:whitespace]];
[userName UserLogin:self.idTextField.text andPassWordExists:self.passwordTextField.text completionHandler:^(id responseObject, NSError *error) {
if (responseObject != nil) {
NSString *userN,*name;
NSArray *object = [responseObject objectAtIndex:0];
userN = [object valueForKey"userName"];
name = [object valueForKey"name"];
self.idTextField = nil;
self.passwordTextField = nil;
LHAppDelegate *appDelegate = (LHAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.loginSession setString:[userN lowercaseString]];
[appDelegate.nameOfUser setString:name];
}else{
[self CustomAlert"Sorry Login Failed, User and/or Passsword Incorrect"];
}
[indicatorView stopAnimating];
[indicatorView removeFromSuperview];
indicatorView = nil;
[loadingView removeFromSuperview];
loadingView = nil;
}];
}
我正在尝试做的是编程,因此当用户登录时,它们会以模态方式出现在标签栏 Controller 中。
目前,当我点击带有错误凭据的按钮时,我会看到我的自定义警报,但它仍然会将我带到标签栏 Controller 。
基本上我想做的是围绕当前的模态转义设置一个条件。这可能吗?
我找到了这段代码:
[self performSegueWithIdentifier: @"MySegue"sender: self];
我将它添加到我的登录方法中:
- (void)Login
{
NSString *rawString = [self.idTextField text];
NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
[self.idTextField setText:[rawString stringByTrimmingCharactersInSet:whitespace]];
[userName UserLogin:self.idTextField.text andPassWordExists:self.passwordTextField.text completionHandler:^(id responseObject, NSError *error) {
if (responseObject != nil) {
NSString *userN,*name;
NSArray *object = [responseObject objectAtIndex:0];
userN = [object valueForKey"userName"];
name = [object valueForKey"name"];
self.idTextField = nil;
self.passwordTextField = nil;
LHAppDelegate *appDelegate = (LHAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.loginSession setString:[userN lowercaseString]];
[appDelegate.nameOfUser setString:name];
[self performSegueWithIdentifier: @"MySegue" sender: self];
}else{
[self CustomAlert"Sorry Login Failed, User and/or Passsword Incorrect"];
}
[indicatorView stopAnimating];
[indicatorView removeFromSuperview];
indicatorView = nil;
[loadingView removeFromSuperview];
loadingView = nil;
}];
}
当我使用错误的凭据登录时,它仍然会将我带到标签栏 Controller
在上述场景中,它将始终执行不受服务器响应影响的 segue,因为 segue 是通过按钮单击执行的。 为避免这种情况,请按以下方式进行:
现在,当您响应成功时,请调用以下电话
[self performSegueWithIdentifier"segueIdentifier"sender:self]
如果要传递参数,请执行以下功能:
-(void)prepareForSegueUIStoryboardSegue *)segue senderid)sender
关于ios - Objective-C 以编程方式呈现模态序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31858751/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |