我正在提供一个自定义机制来在导航栏中创建标题.我有另一个成功使用相同技术的vIEwcontroller.在vIEwDIDAppear上我开火了:
- (voID)addTitleTextFIEld{ CGRect textFrame = self.parentVIEwController.navigationController.navigationbar.frame; textFrame.size.wIDth = 300.0; textFrame.origin.y = (768.0 - 300.0)/2; textFrame.size.height = 30.0; textFrame.origin.x = 7.0; self.TitleTextFIEld = [[UITextFIEld alloc] initWithFrame:textFrame]; self.TitleTextFIEld.placeholder = NSLocalizedString(@"New Multiple Choice Quiz",@"New Multiple Choice Quiz"); self.TitleTextFIEld.borderStyle = UITextborderStyleRoundedRect; self.TitleTextFIEld.Font = [UIFont boldSystemFontOfSize:20.0]; self.TitleTextFIEld.textAlignment = NSTextAlignmentCenter; self.TitleTextFIEld.backgroundcolor = [UIcolor whitecolor]; self.TitleTextFIEld.textcolor = [UIcolor blackcolor]; self.TitleTextFIEld.delegate = self; [self.TitleTextFIEld setautocorrectionType:UITextautocorrectionTypeNo]; self.TitleTextFIEld.clearbuttonMode = UITextFIEldviewmodeWhileEditing; [self.TitleTextFIEld setautocAPItalizationType:UITextautocAPItalizationTypeNone]; self.activeTextFIEld = self.TitleTextFIEld; self.parentVIEwController.navigationItem.TitleVIEw = self.TitleTextFIEld; [self.TitleTextFIEld becomeFirstResponder];}
self.TitleTextFIEld将允许我设置文本值,但如果使用canBecomeFirstResponder进行检查,则返回NO.如您所见,我在parentVIEwController上设置它.我已经尝试使用委托来尝试让parentVIEwController进行设置.当我执行委托并检查textFIEld是否可以成为第一个响应者时它返回YES,但我仍然无法让它接受firstResponder顺序.有任何想法吗? Docs说“如果当前响应者可以辞退第一响应者状态(canResignFirstResponder)并且新响应者可以成为第一响应者”,则响应者对象仅成为第一响应者.
解决方法 你是否告诉UITextFIEld成为后台线程的选择器?[textFIEld performSelectorOnMainThread:@selector(becomeFirstResponder) withObject:nil waitUntilDone:YES];
基本原理:在主线程以外的方法上调用UIKit方法(即更新视图)将不起作用. .这可能会发生. (目前尚不清楚从哪里调用addTitleTextFIEld方法).
还有另一个第一响应者需要一些时间辞职吗?
[textFIEld performSelectorOnMainThread:@selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
理由:如果另一个字段挂在第一个响应者身上(或者在辞职过程中),它会给它时间来清理一个辞职,等到下一个运行循环. . . . .通常下一个运行循环将有足够的时间让前一个响应者清理,或者你可以尝试像0.05这样的短暂延迟.
总结以上是内存溢出为你收集整理的ios – UITextField不会成为FirstResponder全部内容,希望文章能够帮你解决ios – UITextField不会成为FirstResponder所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)