gpt4 book ai didi

ios - [NSTaggedPointerString 文本] : unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-29 12:09:57 26 4
gpt4 key购买 nike

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

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 获取文本时,出现了问题。为了在编辑文本字段和 TextView 后关闭键盘,我将它们设置为 View Controller 的委托(delegate)。以下是部分代码:

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

我猜这是因为当尝试查询并将值分配给文本字段和 TextView 时,该值可能为零。如果有人能告诉我我可能犯的错误是什么?

最佳答案

关闭键盘时缺少

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

关于ios - [NSTaggedPointerString 文本] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33748416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com