【问题标题】:[NSTaggedPointerString text]: unrecognized selector sent to instance[NSTaggedPointerString text]:发送到实例的无法识别的选择器
【发布时间】:2017-04-07 08:48:50
【问题描述】:

我是使用 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"]];
    }
}

我猜这是因为在尝试查询并将值分配给文本字段和文本视图时,该值可能为零。请谁能告诉我我可能犯的错误是什么?

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-23
      • 2018-09-28
      • 2019-08-28
      • 2012-07-24
      相关资源
      最近更新 更多