iOS 中常用到的,又懒得记的点~

带点的数字键盘
场景:输入金额时用到

 textFiledMoney.keyboardType = UIKeyboardTypeDecimalPad;

(0,0)点开始布局

 if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets =NO;
    }

tableview collectionview 刷新指定组和cell

//一个section刷新
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1]; //你需要更新的组数
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];  

//一个cell刷新.    
//你需要更新的组数中的cell
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

collection 相同

iOS 界面跳转卡住 但是不崩溃问题!!!

  • 原因是在rootviewcontroller 触发了右滑手势
  • 此种情况出现在自定义导航控制器返回按钮,防止滑动返回失效
    自定义返回按钮代码
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    if (self.viewControllers.count > 0) {
        TSLog(self.viewControllers.count);
        ///第二层viewcontroller 隐藏tabbar
        viewController.hidesBottomBarWhenPushed=YES;
                UIButton * btn  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
                [btn setImage:[UIImage imageNamed:@"navbar_icon_back"] forState:UIControlStateNormal];
                 btn.title = @"返回";
                 btn.titleFont = 16;
                viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
       
                [btn addTarget:self action:@selector(returnCustom) forControlEvents:UIControlEventTouchUpInside];
        
         // 如果自定义返回按钮后, 滑动返回可能失效, 需要添加下面的代码
          __weak typeof(viewController)Weakself = viewController;
           self.interactivePopGestureRecognizer.enabled = [self.viewControllers count] > 1 ;
           self.interactivePopGestureRecognizer.delegate = (id)Weakself;
     
    }
    [super pushViewController:viewController animated:animated];
}

其中重要的代码

//[self.viewControllers count] 控制是否响应滑动手势
self.interactivePopGestureRecognizer.enabled = [self.viewControllers count] > 1 ;

你可能感兴趣的:(iOS 中常用到的,又懒得记的点~)