1.在更新window.rootViewController时,需要先将window上面的view移除
If the window has an existing view hierarchy, the old views are removed before the new ones are installed.
UIViewController *oldVC = [UIApplication sharedApplication].delegate.window.rootViewController;
for (UIView *view in oldVC.view.subviews) {
[view removeFromSuperview];
}
[oldVC.view removeFromSuperview];
[UIApplication sharedApplication].delegate.window.rootViewController = nil;
2.今天看到一个新奇的东西IFTTT自动化服务,等有时间研究一下
3.队列和线程的关系
串行队列一定是绑定着某一个线程,但是可能会改变。但是队列和线程池到底什么关系,目前不清楚。在并发队列中也是有可能通过主线程执行任务 例如:
//虽然将任务添加到了并发队列,但是执行任务确实主线程,所以会等待任务执行完
dispatch_sync(dispatch_get_global_queue(0, 0), ^{
});
4.安全的通过KVC设置内部变量
//A类包含一个私有属性injector
class A {
@property (nonatomic, weak, nullable) id<BSInjector> injector;
}
- (void)injectInjector:(id)object {
objc_property_t objc_property = class_getProperty([object class], "injector");
if (objc_property == NULL) {
return;
}
const char *attributes = property_getAttributes(objc_property);
NSString *attrStr = [NSString stringWithUTF8String:attributes];
NSRange startRange = [attrStr rangeOfString:@"<BSInjector>"];
if (startRange.location != NSNotFound) {
[object setValue:self forKey:@"injector"];
}
}
5. 解决performSelector警告
SEL selector = NSSelectorFromString(@"didSetupModules");
IMP imp = [module methodForSelector:selector];
void (*func)(id, SEL) = (void *)imp;
func(module, selector);
5. definesPresentationContext属性的使用
当一个视图控制器以 OverCurrentContext 的方式被呈现时,它会向上寻找一个 definesPresentationContext 属性为真的父视图控制器,并在它之上显示这个视图控制器。
UISearchController 仅支持 OverCurrentContext、Popover 因此默认情况下使用的就是 OverCurrentContext 方式
6. UISearchController的正确使用
当在A控制器内使用UISearchController时,有几个重要点要注意:
- 要设置A的
definesPresentationContext = true - 将
UISearchController的searchBar添加到A上,这里我目前了解到的添加方式有两种
* navigationItem.searchController = searchController 添加到导航下面
* self.tableView.tableHeaderView = searchController.searchBar 添加到t`ableview`上
* searchController.searchBar不要直接添加到view上,会导致搜索时searchBar的UIBackground(私有类)的frame不正确(不能顶到屏幕最上面)
* 不要设置searchBar的frame,可能会导致UIBackground的frame不正确
3.self.navigationController?.navigationBar.isTranslucent = false导航是否透明,也会影响searchBar偏移量的行为,这里可以通过设置UITableView的contentInset来调整
4. 我还遇到过UISearchController 和 A的frame没有对齐的问题,可以通过设置UISearchController的view的frame来调整
总之,UISearchController的奇怪行为有很多,查阅了很多资料和官方文档,没有特别好的控制方案
7. cocoaPod问题修复
Errno::ENOENT - No such file or directory @ rb_check_realpath_internal - /Users/maqihan/Desktop/Signal-iOS-main/Pods/SignalRingRTC/out/release/libringrtc/ringrtc.h
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/project.rb:326:in `realpath'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/project.rb:326:in `realpath'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/project.rb:326:in `reference_for_path'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/project.rb:269:in `add_file_reference'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:228:in `block (2 levels) in add_file_accessors_paths_to_pods_group'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:227:in `map'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:227:in `block in add_file_accessors_paths_to_pods_group'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:217:in `each'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:217:in `flat_map'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:217:in `add_file_accessors_paths_to_pods_group'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:99:in `block in add_source_files_references'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/user_interface.rb:149:in `message'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:98:in `add_source_files_references'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb:49:in `install!'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator.rb:102:in `block in install_file_references'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/user_interface.rb:149:in `message'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/pods_project_generator.rb:100:in `install_file_references'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer/xcode/single_pods_project_generator.rb:17:in `generate!'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer.rb:320:in `block in create_and_save_projects'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/user_interface.rb:64:in `section'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer.rb:315:in `create_and_save_projects'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer.rb:307:in `generate_pods_project'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer.rb:183:in `integrate'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/installer.rb:170:in `install!'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/command/install.rb:52:in `run'
/Users/maqihan/.rvm/gems/ruby-2.7.6/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/lib/cocoapods/command.rb:52:in `run'
/Users/maqihan/.rvm/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/cocoapods-1.13.0/bin/pod:55:in `<top (required)>'
/Users/maqihan/.rvm/gems/ruby-2.7.6/bin/pod:23:in `load'
/Users/maqihan/.rvm/gems/ruby-2.7.6/bin/pod:23:in `<main>'
/Users/maqihan/.rvm/gems/ruby-2.7.6/bin/ruby_executable_hooks:22:in `eval'
/Users/maqihan/.rvm/gems/ruby-2.7.6/bin/ruby_executable_hooks:22:in `<main>'
昨天下载signal-ios运行没问题,今天早上来了,编译就报错了,我啥也没动。后来通过删除pod的缓存解决问题
~/Library/Caches/CocoaPods/Pods/Release 下报错的库(我这个案例不需要删除,只需删除下面的,因为siganl使用的库都不是release的)
~/Library/Caches/CocoaPods/Pods/Specs 全部删除
然后`pod install`