Xcode11 iOS13问题汇总

问题一:报错 Multiple methods named 'numberOfItemsInSection:' found with mismatched result, parameter type or attributes

这个问题是由于二维数组取值时,编译器不知道是什么对象,调用对象的方法会报错,在Xcode之前的版本没有问题,解决方法是,告诉编译器是什么类型,我的是UICollectionView类型,如下:

解决前:

NSInteger numberOfBeforeSection = [_update[@"oldModel"] numberOfItemsInSection:updateItem.indexPathBeforeUpdate.section];

解决后:

 NSInteger numberOfBeforeSection = [(UICollectionView *)_update[@"oldModel"] numberOfItemsInSection:updateItem.indexPathBeforeUpdate.section];

问题二:夜间模式,大致是把没有设置背景色的系统控件会被设置成黑色,一些控件是tintColor没设置的话也会被改。

如下方式可以避免页面被改动,将来如果有设计夜间模式的话,再进行处理

配置方式有两种,单页面配置 和 全局配置。

    单页配置
    将需要配置的 UIViewControler 对象的 overrideUserInterfaceStyle 属性设置成 UIUserInterfaceStyleLight 或者 UIUserInterfaceStyleDark 以强制是某个页面显示为 浅/深色模式

    全局配置
    在工程的Info.plist的中,增加/修改 UIUserInterfaceStyle为UIUserInterfaceStyleLight或UIUserInterfaceStyleDark

问题三:UISearchBar 的页面crash

因为这一句代码:UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];

Xcode 11 应该是做了限制访问私有属性的一些处理。然后增加了searchTextField属性,但是是只读的,不能设置属性,所以还得通过遍历子view获取到,改动如下:

NSString *version = [UIDevice currentDevice].systemVersion;
      if ([version floatValue] >= 13.0) {
            UITextField *textField = self.searchBar.searchTextField;
            textField.backgroundColor = [UIColor whiteColor];
            textField.textColor= CIDarkGrayTextColor;
            textField.font= [UIFont systemFontOfSize:14];
         

      } else {
          // 针对 13.0 以下的iOS系统进行处理
          UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];
             
             if(searchField) {
                //这里设置相关属性
                 
             }else{}
      }

获取SearchBar的cancleButton

if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 13.0) {
  for(id cc in [self.searchBar subviews]) {
    for (id zz in [cc subviews]) {
      for (id gg in [zz subviews]) {
        if([gg isKindOfClass:[UIButton class]]){
          UIButton *cancelButton = (UIButton *)gg;
          [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }
      }
    }
  }
}else{
  UIButton*cancelButton = (UIButton *)[self.searchBar getVarWithName:@"_cancelButton"];
  [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}

问题四:present到登录页面时,发现新页面不能顶到顶部,更像是Sheet样式,如下图:

原因是iOS 13 多了一个新的枚举类型 UIModalPresentationAutomatic,并且是modalPresentationStyle的默认值。

UIModalPresentationAutomatic实际是表现是在 iOS 13的设备上被映射成UIModalPresentationPageSheet

但是需要注意一点PageSheetFullScreen 生命周期并不相同

FullScreen会走完整的生命周期,PageSheet因为父视图并没有完全消失,所以viewWillDisappear及viewWillAppear并不会走,如果这些方法里有一些处理,还是换个方式,或者用FullScreen

设置方法:

    CILoginVC *vc = [[CILoginVC alloc] init];
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:vc animated:YES completion:nil];

关注IT美学公众号,分享更多知识

猜你喜欢

转载自blog.csdn.net/bitcser/article/details/100113549