- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在执行 NSURLResquest 和加载节目之前按下键盘...
[self.txtComentario resignFirstResponder];
应用程序崩溃...我也已经尝试在 loadingThread() 中 resignFirstResponder
-(void) loadingThread {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[self.myLoadingView setFrame:CGRectMake(0, 0, 320, 568)];
[self.myLoadingImagem setFrame:CGRectMake(133, 250, 54, 9)];
[appDelegate.window addSubview:self.myLoadingView];
[appDelegate.window addSubview:self.myLoadingImagem];
[self.myLoadingView setHidden:NO];
[self animar];
}
-(IBAction)btnComentarClick:(id)sender {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[self.txtComentario resignFirstResponder];
[NSThread detachNewThreadSelector:@selector(loadingThread) toTarget:self withObject:nil];
NSString* comentarios = [kBaseURL stringByAppendingPathComponent:kComentarios];
NSURL* url = [NSURL URLWithString:comentarios]; //1
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST"; //2
// NSDictionary *usuarioDict = [[NSDictionary alloc] initWithObjectsAndKeys:txtEmailCadastro.text, @"email", txtSenhaCadastro.text, @"senha", categorias, @"categorias", nil];
NSMutableDictionary* jsonable = [NSMutableDictionary dictionary];
safeSet(jsonable, @"idUsuario", appDelegate.usuarioLogado.identificador);
safeSet(jsonable, @"nomeUsuario", appDelegate.usuarioLogado.nome);
safeSet(jsonable, @"textoComentario", self.txtComentario.text);
safeSet(jsonable, @"idOcorrencia", _location._id);
NSData* data = [NSJSONSerialization dataWithJSONObject:jsonable options:0 error:NULL]; //3
request.HTTPBody = data;
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; //4
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession* session = [NSURLSession sessionWithConfiguration:config];
NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { //5
if (!error) {
// NSArray* responseArray = @[[NSJSONSerialization JSONObjectWithData:data options:0 error:NULL]];
NSLog(@"comentado");
dispatch_async(dispatch_get_main_queue(), ^(void){
self.txtComentario.text = @"";
[self.txtComentario resignFirstResponder];
});
}
}];
[dataTask resume];
[self listarComentarios];
}
编辑:如果我尝试在 NSThread 之前 resignFirstesponder,什么也没有发生,没有崩溃但键盘按下没有。如果我尝试在 loadingThread 中...应用程序崩溃
NSThread 内部的错误是:
[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
最佳答案
有时,异步 API 请求不会回调到主线程上的委托(delegate)。因此,请尝试确保您位于主线程上。如果您不在其中,请在对 UI 进行任何更新之前尝试切换到主线程。
if ([NSThread isMainThread]) {
NSLog(@"Yes, it is!");
} else {
NSLog(@"No, it's not. Please switch to main");
}
关于ios - ResignFirstResponder 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28454254/
我有一个很简单的CustomIDatePicker写在 中的类 swift 5 ,顶部有一个工具栏,其中包含一个“完成”按钮。问题是,按下此按钮时键盘从未缩回。我尝试了4种不同的方法,请参阅下面的详细
我正在使用 TPKeyboardAvoiding在我的应用程序中显示键盘时隐藏移动文本字段,但是当我尝试结束编辑文本字段时出现异常。它来自 TPKeyboardAvoiding 中的这个方法: - (
我有 uitextfield 在 uitableview 中输入国家/地区值。当点击该字段时,我将显示已加载国家/地区值的表格 View 。 点击任何单元格时,它会返回到相同的表单,并将所选值添加到国
我有一个带有两个文本字段和一个按钮的LoginViewController。我使用了 Storyboard,因此这些不是以编程方式创建的。它们位于彼此之下。 这是 .h 文件 @interface L
我有一个名为“fieldPassword”的文本字段声明为 IBOutlet @property (strong, nonatomic) IBOutlet UITextField *fieldPass
我正在尝试在执行 NSURLResquest 和加载节目之前按下键盘... [self.txtComentario resignFirstResponder]; 应用程序崩溃...我也已经尝试在 lo
我有一个模态呈现的 View ,其中包含 3 个标签。 第三个标签不应该是可编辑的,并且应该在点击它时显示一个 UIDatePicker,如果它显示则隐藏键盘。 所以我这样做了: - (BOOL)te
我是使用 Swift 进行 stackoverflow 和 iOS 应用程序开发的新手。当我想在我的应用程序中关闭键盘时,我连接 viewcontroller.swift 中的 uitextfield
只有当所有 textFields 都已填充时,我才想为一个 textField resignFirstResponder()。但是由于某种原因它不起作用。不管其他人是否被填满,它只检查一个响应者。 这
我有一个 UITextField 和一个 UIButton。如果在文本字段处于事件状态时点击按钮,我想关闭键盘,但我无法这样做。我尝试在点击按钮时调用 [textField resignFirstRe
我有三个文本框。 vacDate vacTime vacType 当我点击 vacDate 或 vacTime 时,我会显示日期选择器 myDatePicker。 此外,当我点击任何地方时,我会调用隐
我不想显示键盘,而是想在选择文本字段时显示弹出 View (我的代码在底部)。如果键盘没有显示,那么一切正常。但是,如果显示键盘然后选择文本字段,则键盘不会被关闭,firstResponders 一定
首先为我糟糕的英语感到抱歉!! 在我的应用程序中有一个 UIViewController 并且 UIView 在 subViewLogin 中被称为 subViewLogin 有 2 个 UIText
在登录页面中,有两个文本输入框(text1和text2)用于输入用户名和密码。单击登录后,它会在这两个文本框上调用两个 resignFirstResponder。我想知道为什么需要调用这个方法? 最佳
我在 UIWindow 上添加了一个自定义 View (NotifyView),带有关闭按钮(将其从 UIWindow 中删除)。当 PUSH 通知进入 didReceiveRemoteNotific
我正在开发一个应用程序,它有一个 tableView,每个单元格的右侧都有一个 textField(有 20 多个单元格)。除了最后一行,我已经为每一行创建了自定义单元格。最后一行只有一个按钮。 现在
我有一种情况,键盘可能打开,然后 NSTimer 在 TextView 上弹出一个 View 。无论如何要全局关闭键盘而不是从 TextView resignFirstResponder 方法?我问的
-(IBAction)settings:(id)sender { [mileagerate resignFirstResponder]; [mainView bringSubviewT
我有一个第三方键盘,目前包含一个 UISearchBar(即启动时的第一响应者)并且用户能够搜索内容(即 gif)以便能够复制、粘贴、发送给 friend 等。 理论上,在栏中输入文本并按下搜索后,用
这个问题在这里已经有了答案: How do I dismiss the iOS keyboard? (16 个答案) hiding keyboard ios [duplicate] (4 个回答) 关
我是一名优秀的程序员,十分优秀!