- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在尝试使用 prepare for segue 方法执行一个 segue。我在关注这个问题 this但我无法成功注册。当我单击注册按钮时,它所做的只是注册用户并停在那里。我从 View Controller (而不是按钮本身)模态地连接了我的 segue,所以那个没有问题。我的发送 View 只是一个带有文本字段和完成按钮的普通 View ,而我的接收 View 是一个静态 TableView ,行上有一个标签(称为 nameLabel)。
2 个问题
1.我的 prepare for segue 方法中缺少什么?(我还使用 parse 作为后端,所以这就是 PFLogInSuccessNotification 的来源)
感谢您花时间提供帮助。
**my segue method**
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"can you see this");
if ([segue.identifier isEqualToString:@"SegueTOprofile"])
{
if (PFLogInSuccessNotification) {
profileTableViewController *myProfileView = (profileTableViewController *)[segue destinationViewController];
PFUser *user =[PFUser user];
user.username = myProfileView.nameLabel.text;
// NSLog(@"%@",myProfileView.nameLabel.text);
}
}
[self performSegueWithIdentifier:@"SegueTOprofile" sender:self];
}
**这是我的注册 View **.h
#import <UIKit/UIKit.h>
extern NSString *const PFSignUpSuccessNotification;
extern NSString *const PFSignUpFailureNotification;
@interface SignUpViewController : UIViewController<UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *emailNameField;
@property (strong, nonatomic) IBOutlet UITextField *passwordField;
@property (strong, nonatomic) IBOutlet UIButton *signupButton;
- (IBAction)SignUp:(id)sender;
@property (strong, nonatomic) IBOutlet UITextField *repeatPasswordField;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *BackButton;
@property (strong, nonatomic) IBOutlet UITextField *usernameField;
.m
#import "SignUpViewController.h"
#import "profileTableViewController.h"
#import <Parse/Parse.h>
#import "ActivityView.h"
#import "TabBarCustomClassViewController.h"
@interface SignUpViewController ()
-(void)processFieldEntries;
- (void)textInputChanged:(NSNotification *)note;
- (BOOL)shouldEnableDoneButton;
@end
@implementation SignUpViewController
@synthesize signupButton = _signupButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_usernameField];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_emailNameField];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_passwordField];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_repeatPasswordField];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == _usernameField) {
[_usernameField becomeFirstResponder];
}
if (textField == _emailNameField) {
[_emailNameField becomeFirstResponder];}
if (textField == _passwordField) {
[_passwordField becomeFirstResponder];
}
if (textField == _repeatPasswordField) {
[_repeatPasswordField becomeFirstResponder];
}
return YES;
}
-(BOOL)shouldEnableDoneButton
{
BOOL enableDoneButton = NO;
if (_emailNameField.text != nil && _passwordField.text != nil && _repeatPasswordField != nil && _usernameField.text != nil) {
enableDoneButton = YES;
}
return enableDoneButton;
}
/*
// Using segue --> Send the current selected profile to "ProfileView"
ProfileViewController *aProfileView = (ProfileViewController *)[segue destinationViewController];
aProfileView.currentProfile = selectedProfile; */
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"can you see this");
if ([segue.identifier isEqualToString:@"SegueTOprofile"])
{
if (PFLogInSuccessNotification) {
profileTableViewController *myProfileView = (profileTableViewController *)[segue destinationViewController];
PFUser *user =[PFUser user];
user.username = myProfileView.nameLabel.text;
// NSLog(@"%@",myProfileView.nameLabel.text);
}
}
[self performSegueWithIdentifier:@"SegueTOprofile" sender:self];
}
-(void)textInputChanged:(NSNotification *)note
{
_signupButton.enabled = [self shouldEnableDoneButton];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)SignUp:(id)sender {
[_usernameField resignFirstResponder];
[_emailNameField resignFirstResponder];
[_passwordField resignFirstResponder];
[_repeatPasswordField resignFirstResponder];
[self processFieldEntries];
}
-(void)processFieldEntries
{
// Check that we have a non-zero username and passwords.
// Compare password and passwordAgain for equality
// Throw up a dialog that tells them what they did wrong if they did it wrong.
NSString *email = _emailNameField.text;
NSString *passwordd = _passwordField.text;
NSString *passwordAgainn = _repeatPasswordField.text;
NSString *username = _usernameField.text;
NSString *errorText = @"Please ";
NSString *usernameBlankText = @"enter a username";
NSString *passwordBlankText = @"enter a password";
NSString *joinText = @", and ";
NSString *passwordMismatchText = @"enter the same password twice";
BOOL textError = NO;
if (email.length == 0 || passwordd.length == 0 || passwordAgainn.length == 0) {
textError = YES;
// Set up the keyboard for the first field missing input:
if (passwordAgainn.length == 0) {
[_repeatPasswordField becomeFirstResponder];
}
if (passwordd.length == 0) {
[_passwordField becomeFirstResponder];
}
if (username.length == 0) {
[_usernameField becomeFirstResponder];
}
if (email.length == 0) {
errorText = [errorText stringByAppendingString:usernameBlankText];
}
if (passwordd.length == 0 || passwordAgainn.length == 0) {
if (email.length == 0) { // We need some joining text in the error:
errorText = [errorText stringByAppendingString:joinText];
}
errorText = [errorText stringByAppendingString:passwordBlankText];
}
} else if ([passwordd compare:passwordAgainn] != NSOrderedSame) {
// We have non-zero strings.
// Check for equal password strings.
if (_signupButton.enabled == YES) {
textError = YES;
errorText = [errorText stringByAppendingString:passwordMismatchText];
}
}
if (textError) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:errorText message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertView show];
return;
}
// Everything looks good; try to log in.
// Disable the done button for now.
_signupButton.enabled = NO;
ActivityView *activityView = [[ActivityView alloc] initWithFrame:CGRectMake(0.f, 0.f, self.view.frame.size.width, self.view.frame.size.height)];
UILabel *label = activityView.label;
label.text = @"Signing You Up";
label.font = [UIFont boldSystemFontOfSize:20.f];
[activityView.activityIndicator startAnimating];
[activityView layoutSubviews];
[self.view addSubview:activityView];
// Call into an object somewhere that has code for setting up a user.
// The app delegate cares about this, but so do a lot of other objects.
// For now, do this inline.
PFUser *user = [PFUser user];
user.email = email;
user.password = passwordAgainn;
user.username = username;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[[error userInfo] objectForKey:@"error"] message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertView show];
_signupButton.enabled = [self shouldEnableDoneButton];
[activityView.activityIndicator stopAnimating];
[activityView removeFromSuperview];
// Bring the keyboard back up, because they'll probably need to change something.
[_emailNameField becomeFirstResponder];
return;
}
// Success!
[activityView.activityIndicator stopAnimating];
[activityView removeFromSuperview];
}];
}
@end
最佳答案
prepareForSegue 不执行转场,它是您可以将数据传递到目标 View Controller 的地方。如果您从 Controller (而不是按钮)连接了 segue,则必须使用 performSegueWithIdentifier:sender: 手动调用 segue:
如果你想用这一行触发它:
[self shouldPerformSegueWithIdentifier:@"SegueTOprofile" sender:self];
应该是:
[self performSegueWithIdentifier:@"SegueTOprofile" sender:self];
我无法判断这是否是您的意图,因为您在代码中使用了 2 个不同的 segue 标识符。
关于ios - 无法使用 prepare for segue 方法执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18732534/
我一整天都遇到同样的错误,我知道这是在说 Storyboard 中没有识别出 segue,但确实如此。以下是我认为相关的代码:1.为 segue 发出信号的按钮的 IBAction。 -(IBActi
我有一个从 A View Controller 到 B View Controller 的 unwind segue。 在B中做了一个网络操作,操作完成后,响应会显示在A View Controlle
我正在创建一个应用程序,家长可以在其中登录并查看有关其本地托儿中心的信息。但是,为登录运行 View Controller 的代码无法正常工作。一旦用户按下登录按钮,我希望我的代码使用标识符“Show
刚刚遇到一个奇怪的问题。我有一个启动画面,它自动使用自定义 segue (fade-to-segue) 转到主页 ViewController。自定义 segue 工作正常,但一旦实现,我在主页上的其
以编程方式创建的 segue 在 performSegueWithIdentifier: 上使应用程序崩溃,不过我真的不想使用 Storyboard。 - (void)viewDidLoad { [s
我想我一定在这里遗漏了一些简单的东西,但我不知道它是什么。 我必须支持来自同一个 View Controller 的多个 segue,所以我很自然地想使用 segue 标识符。我的代码由于某种原因无法
当用户在警告时点击“确定”按钮时,我如何才能将用户带到自定义 View Controller ? 我有一个主 Controller -> 导航 Controller -> 第二个 View Contr
在 TableView Controller 中,我试图获取在我继续之前选择的行的索引(最终将传递此信息以准备继续)。我已经实现了这个功能: var selectedQuestionCell: Ind
我正在 Xamarin Studio 中开发一个应用程序(所以它是 C#),它有一个包含多个 TextField 的表单,我想在 segue 之前验证整个屏幕> 到下一个屏幕执行。单击按钮时,它正在使
我有一个带有标识符的 segue。 当我按下函数 shouldPerformSegueWithIdentifier 中的按钮时,我得到一个空标识符 什么会导致这样的问题?我设置错了什么? 这是我的代码
我有一个奇怪的问题。我在 Storyboard中创建了 2 个 View Controller :testSegueViewcontroller 和 nextPageViewController。 t
我下面的代码试图将一个值从 twoviewcontroller 转移到 View Controller 。 segue 正在工作,我可以从 View Controller 转到 View Contro
我正在尝试使用自定义segue,当单击按钮时,它会使 View 向右或向左“滚动”。我添加了一个如下所示的自定义类 class horizontalSegue : UIStoryboardSegue
我有一个带有 Root View Controller 的 UINavigationController。我的 UINavigationController 也设置为我的应用程序的 Initial V
您好,我正在尝试使用 prepare for segue 方法执行一个 segue。我在关注这个问题 this但我无法成功注册。当我单击注册按钮时,它所做的只是注册用户并停在那里。我从 View Co
当 Storyboard上有一个按钮连接退出时,我了解如何使用展开转场。但是在我的应用程序中,我使用推送转场从 TableViewController 转到 ViewController。所以我的导航
我要实现的目标的背景: MainViewController 呈现 TableVC。我将点击一个单元格以显示 DetailVC。能够通过 TableVC 或 DetailVC 上导航栏上的 doneB
在我的 Storyboard中,模态转场将用户带到登录屏幕(从主屏幕)。然后,我从注册屏幕添加了一个 PUSH segue 到下一个屏幕(创建配置文件),该屏幕嵌入在导航 Controller 中(创
我有大约 6 个 segue 在 prepareForSegue 方法中执行相同的操作,但是,我想为我的 unwind segue 跳过此操作,但我无法弄清楚如何确定传递的 segue 是 unwin
因此,我开始在XCode 4.3.2中使用 Storyboard 。我从Master-Detail应用程序(iPad的拆分 View 应用程序)开始。在详细信息 View (名为DetailVC)中,
我是一名优秀的程序员,十分优秀!