[NSTaggedPointerString text]:发送到实例

时间:2015-11-17 03:01:39

标签: ios objective-c

我是使用Objective-c进行iOS编程的初学者。我现在正在处理我的项目,并在视图控制器中发现了这个奇怪的错误。

2015-11-16 20:17:10.631 WeMakeFriends[1860:67214] -[NSTaggedPointerString text]: unrecognized selector sent to instance 0xa00296c6c756e286
2015-11-16 20:17:10.635 WeMakeFriends[1860:67214] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'[NSTaggedPointerString text]: unrecognized selector sent to instance 0xa00296c6c756e286'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000106e3af45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001068b4deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000106e4356d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000106d90eea ___forwarding___ + 970
    4   CoreFoundation                      0x0000000106d90a98 _CF_forwarding_prep_0 + 120
    5   WeMakeFriends                       0x0000000105f49f4c -[EditProfileViewController saveInfo:] + 108

似乎当我尝试从UITextField或UITextView获取文本时,出了点问题。为了在编辑文本字段和文本视图后关闭键盘,我将它们设置为视图控制器的委托。 以下是代码的一部分:

@interface EditProfileViewController () <UITextViewDelegate, UITextFieldDelegate>

@property (strong, nonatomic) IBOutlet UITextField *username;
@property (strong, nonatomic) IBOutlet UITextField *userAge;
@property (strong, nonatomic) IBOutlet UITextField *school;
@property (strong, nonatomic) IBOutlet UITextField *phone;
@property (strong, nonatomic) IBOutlet UITextView *something;
@property DatabaseManager *dbManager;
@property NSArray *queryResult;
@property (copy, )NSString *textviewCopy;
@end

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //[self registerForKeyboardNotifications];
// set UITextView placeholder text
    [self.something setText:@"I want to ..."];
    self.something.textColor = [UIColor lightGrayColor];
// initialize the database manager
    _dbManager = [[DatabaseManager alloc] initWithDatabaseFilename:@"users.sql"];

// load the user data if you inserted it before and come back to this view controller again
    if (self.currentUser.name.length != 0) {
        [self loadUser];
    } else {
    // load the user data from the database
        [self checkIfExists];
    }
    self.checkLaunch = 1;
}

- (IBAction)saveInfo:(id)sender {
    self.currentUser.username = [self.username text];
    self.currentUser.phone = [self.phone text];
    _currentUser.age = [self.userAge text];
    _currentUser.school = [self.school text];
}

-(void) loadUser {
    // load the data out again
    NSString *query = [NSString stringWithFormat:@"select * from Users where name='%@'", self.currentUser.name];
    if (self.queryResult == nil) {
        self.queryResult = [[NSArray alloc] initWithArray:[self.dbManager loadDatafromDB:query]];
    }

    // set the textfields with values if there are any
    if (self.queryResult.count > 0) {
        self.username = [[self.queryResult objectAtIndex:0] objectAtIndex:[self.dbManager.columnNames indexOfObject:@"username"]];
        self.phone = [[self.queryResult objectAtIndex:0] objectAtIndex:[self.dbManager.columnNames indexOfObject:@"phone"]];
        self.something = [[self.queryResult objectAtIndex:0] objectAtIndex:[self.dbManager.columnNames indexOfObject:@"todo"]];
        self.school = [[self.queryResult objectAtIndex:0] objectAtIndex:[self.dbManager.columnNames indexOfObject:@"school"]];
        self.userAge = [[self.queryResult objectAtIndex:0] objectAtIndex:[self.dbManager.columnNames indexOfObject:@"age"]];
    }
}

我猜这是因为在尝试查询并将值分配给textfields和textviews时,值可能为零。如果有人能告诉我,我可能犯的错误是什么?

1 个答案:

答案 0 :(得分:0)

在解雇键盘时,

resignFirstResponder丢失了。试试这个:

- (IBAction)saveInfo:(id)sender {
    [username resignFirstResponder];
    [userAge resignFirstResponder];
    [phone resignFirstResponder];
    [school resignFirstResponder];

    self.currentUser.username = [self.username text];
    self.currentUser.phone = [self.phone text];
    _currentUser.age = [self.userAge text];
    _currentUser.school = [self.school text];
}