我想要在我的代码中做的就是从一个视图移动到另一个视图。无论我尝试以多少不同的方式绕过它,当前视图的任何 segue 或任何更改都会导致此错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
根本没有迹象表明它在谈论什么对象,并且该应用程序在我的 segue 行上崩溃了。哦,我正在使用 Xcode 5-DP 和 iOS 7。这是我的来源:
登录视图控制器.h
#import <UIKit/UIKit.h>
#import "ECSlidingViewController.h"
#import "MenuViewController.h"
#import <MessageUI/MessageUI.h>
#import <CoreData/CoreData.h>
@interface LoginViewController : UIViewController <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *userTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
- (IBAction)signupTouched:(UIButton *)sender;
- (IBAction)logInPressed:(id)sender;
- (IBAction)backgroundTouched:(id)sender;
- (IBAction)revealMenu:(id)sender;
@end
LoginViewController.m(第 8 行的异常)
#import "LoginViewController.h"
#import "RegisterView.h"
#import <Parse/Parse.h>
@implementation LoginViewController
- (IBAction)signupTouched:(UIButton *)sender {
[self performSegueWithIdentifier:@"signup" sender:self];
// THE APPLICATION CRASHES ON THIS LINE ABOVE
}
//Login button pressed
-(IBAction)logInPressed:(id)sender
{
//If user logged succesful:
//[self performSegueWithIdentifier:@"LoginSuccesful" sender:self];
if (![self.userTextField.text isEqual:@""]) {
[PFUser logInWithUsernameInBackground:self.userTextField.text password:self.passwordTextField.text block:^(PFUser *user, NSError *error) {
if (user) {
//Open the wall
//[self performSegueWithIdentifier:@"LoginSuccesful" sender:self];
UIAlertView *loginAlertView = [[UIAlertView alloc] initWithTitle:@"Great!" message:@"You have logged in" delegate:nil cancelButtonTitle:@"Get roaming" otherButtonTitles:nil, nil];
[loginAlertView show];
} else {
//Something bad has ocurred
NSString *errorString = [[error userInfo] objectForKey:@"error"];
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[errorAlertView show];
}
}];
} else {
//Something bad has ocurred
NSString *errorString = @"You did not type any credentials!";
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
[errorAlertView show];
}
}
- (IBAction)backgroundTouched:(id)sender {
[self.userTextField resignFirstResponder];
[self.passwordTextField resignFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
self.slidingViewController.underRightViewController = nil;
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
}
- (IBAction)revealMenu:(id)sender
{
[self.slidingViewController anchorTopViewTo:ECRight];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.userTextField.delegate = self;
self.passwordTextField.delegate = self;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidUnload {
[self setUserTextField:nil];
[self setPasswordTextField:nil];
[super viewDidUnload];
}
@end
我用谷歌搜索过,我已经用谷歌搜索过了。似乎没有其他人遇到过这样的问题。我尝试清理我的整个 iOS 模拟器和一切都无济于事,遵循似乎对其他人有用的解决方案。我已经尝试了所有可能的类型,但没有一个有效。
提前致谢!