项目中遇到的问题(一)
程序员文章站
2022-05-30 17:43:48
...
做开发的项目中难免会遇到一些问题,把这些遇到过的记录下载,方便下次使用查找,好记性不如烂笔头嘛
1、IQKeyboardManager:
键盘弹起后会出现一个toolbar,这时使用其提供的禁用方法完全无效,
// 全局禁用,没法达到我要的效果
[IQKeyboardManager sharedManager].enable = NO;
[IQKeyboardManager sharedManager].enableAutoToolbar = NO;
在IQKeyboardManager.m的源代码时发现有以下一段代码
-(void)addToolbarIfRequired
{
CFTimeInterval startTime = CACurrentMediaTime();
[self showLog:[NSString stringWithFormat:@"****** %@ started ******",NSStringFromSelector(_cmd)]];
// Getting all the sibling textFields.
NSArray *siblings = [self responderViews];
[self showLog:[NSString stringWithFormat:@"Found %lu responder sibling(s)",(unsigned long)siblings.count]];
//Either there is no inputAccessoryView or if accessoryView is not appropriate for current situation(There is Previous/Next/Done toolbar).
//setInputAccessoryView: check (Bug ID: #307)
if ([_textFieldView respondsToSelector:@selector(setInputAccessoryView:)])
{
if ([_textFieldView inputAccessoryView] == nil ||
[[_textFieldView inputAccessoryView] tag] == kIQPreviousNextButtonToolbarTag ||
[[_textFieldView inputAccessoryView] tag] == kIQDoneButtonToolbarTag)
{
// .....
}
}
}
_textFieldView inputAccessoryView] == nil的时候才会去创建toolbar,发现问题就好办了。这时候我们只需要在被响应键盘的textfield中加上 self.inputAccessoryView = [UIView new];
2、跳转至上层控制器
方法一、不推荐
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
方法二、推荐
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[你要跳转到的Controller class]]) {
[self.navigationControllerpopToViewController:controller animated:YES];
}}
方式三、推荐 这种方式可以适合返回指定控制器并调用其方法(比如刷新)
QDHomeController *homeController = nil;
for (UIViewController *vc in currentVC.navigationController.viewControllers) {
if ([vc isKindOfClass:[QDHomeController class]]) {
homeController = (QDHomeController*)vc;
break;
}
}
[currentVC.navigationController popToViewController:homeController animated:YES];
[homeController resetSelectedWithIndex:0];
下一篇: 追了她的闺蜜