問題一:報錯 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
。
但是需要注意一點PageSheet
與 FullScreen 生命週期並不相同
FullScreen會走完整的生命週期,PageSheet因爲父視圖並沒有完全消失,所以viewWillDisappear及viewWillAppear並不會走,如果這些方法裏有一些處理,還是換個方式,或者用FullScreen
設置方法:
CILoginVC *vc = [[CILoginVC alloc] init];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:YES completion:nil];
關注IT美學公衆號,分享更多知識