Я новичок в iOS, работая через учебные пособия. Теперь у меня есть этот кусок кода:iOS NSInvalidArgumentException, непризнанный селектор, отправленный в экземпляр
- (void)viewWillAppear:(BOOL)animated
{
// [super viewWillAppear:animated];
if(self.firstName)
{
NSLog(@"%@",self.firstName);
self.textFieldFirstName.text = self.firstName;
}
}
Во-первых, как указано выше, я должен был закомментировать вызов супер - приложение не хочет, чтобы начать. Во-вторых: присвоение self.textFieldFirstName.text = self.firstName; сбой приложения с SIGABORT и выходом:
2014-10-13 11:50:19.631 PersonalStoryboard[1451:60b] firstName = John
2014-10-13 11:50:19.636 PersonalStoryboard[1451:60b] John
2014-10-13 11:50:19.636 PersonalStoryboard[1451:60b] -[UIView setText:]: unrecognized selector sent to instance 0x8f97470
2014-10-13 11:50:19.639 PersonalStoryboard[1451:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setText:]: unrecognized selector sent to instance 0x8f97470'
*** First throw call stack:
Почему? Заранее спасибо.
Спасибо, ребята. Файл 1:
//
#import "FirstNameEditViewController.h"
@interface FirstNameEditViewController()
@property (strong, nonatomic) IBOutlet UITextField *textFieldFirstName;
@end
@implementation FirstNameEditViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
// [super viewWillAppear:<#animated#>];
if(self.firstName)
{
NSLog(@"%@",self.firstName);
self.textFieldFirstName.text = self.firstName;
}
}
@end
Файл 2:
#define LogPretty NSLog(@"LogPretty:%s %d %s",__FILE__,__LINE__,__PRETTY_FUNCTION__);
#import "PersonalDetailViewController.h"
#import "FirstNameEditViewController.h"
#import "Person.h"
@interface PersonalDetailViewController()
@property (strong, nonatomic) IBOutlet UIButton *buttonFirstName;
@property (strong, nonatomic) IBOutlet UIButton *buttonName;
@property (strong, nonatomic) IBOutlet UIButton *buttonAge;
@property (strong, nonatomic) IBOutlet UIButton *buttonJob;
@property (strong, nonatomic) IBOutlet UIButton *buttonSalary;
@end
@implementation PersonalDetailViewController
{
Person *person;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
person = [[Person alloc] init];
[self showPerson];
}
- (void)showPerson
{
LogPretty
/*
IT CRASHES HERE !!!
[self.buttonFirstName setTitle:person.firstName forState:UIControlStateNormal];
[self.buttonName setTitle:person.name forState:UIControlStateNormal];
[self.buttonJob setTitle:person.job forState:UIControlStateNormal];
[self.buttonAge setTitle:person.age forState:UIControlStateNormal];
[self.buttonSalary setTitle:person.salary forState:UIControlStateNormal];
*/
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonFirstNameTouched:(id)sender {
[self performSegueWithIdentifier:@"firstNameEditSegue" sender:(self)];
}
- (IBAction)buttonNameTouched:(id)sender {
}
- (IBAction)buttonAgeTouched:(id)sender {
}
- (IBAction)buttonJobTouched:(id)sender {
}
- (IBAction)buttonSalaryTouched:(id)sender {
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"identifier = %@",segue.identifier);
if([segue.identifier isEqualToString:@"firstNameEditSegue"])
{
NSLog(@"firstName = %@",person.firstName);
FirstNameEditViewController *editController = segue.destinationViewController;
editController.firstName = person.firstName;
}
}
@end
И, наконец, лицо:
#define LogPretty NSLog(@"%s %d %s",__FILE__,__LINE__,__PRETTY_FUNCTION__);
#import "Person.h"
@implementation Person
- (id) init
{
LogPretty
self = [super init];
if(self)
{
self.firstName = @"John";
self.name = @"Brown";
self.job = @"Developer";
self.age = 35;
self.salary = 35000;
}
return self;
}
@end
я буду greatfull за помощь
Можете ли вы показать, где вы объявляете свое 'self.textFieldFirstName'! Вы хотите, чтобы это был UITextField. Но, очевидно, это «UIView». – BoilingLime
да, нам нужно знать тип 'textFieldFirstName', в противном случае это будет трудно помочь :) – nburk
Я предполагаю, что это' UITextField', но он, вероятно, не установлен правильно, поскольку '[super viewWillAppear]' закомментирован, а не конечно, хотя ... – nburk