常見問題及解決方案

weixin_34321977發表於2016-12-15

使用cocoapods匯入第三方庫找不到標頭檔案

1.選擇target(就是左邊你的工程target)—— BuildSettings —— search Paths 下的 User Header Search Paths

2670204-b5ee579faf25d4fb.png

Block中造成迴圈引用警告

1.在Block外邊宣告弱引用,例如要引用UIViewController型別的self
__block UIViewController *weakSelf = self;
2.Block裡面使用
[weakSelf 需要執行的方法];

OC設定狀態列顏色為白色

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

使用第三方鍵盤IQkeyboard鍵盤彈出,導航條位置上移導致消失問題解決

1.在當前控制器重寫下里面的方法

-(void)loadView
{
    UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.view = scrollview;
}

2.監聽鍵盤出現和消失來更改輸入框的位置(這裡是bottomView)

rac_addObserverForName方法是封裝的方法,可以用系統的

 [[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardWillShowNotification object:nil] subscribeNext:^(NSNotification * x) {
        
        NSDictionary* info = [x userInfo];
        CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
        
        [UIView animateWithDuration:0.25 animations:^{
            self.bottomView.frame = CGRectMake(0, kScreenHeigth - kbSize.height - 45, kScreenWidth, 45);
        }];
    }];
    
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardDidHideNotification object:nil] subscribeNext:^(NSNotification * x) {
        
        [UIView animateWithDuration:0.3 animations:^{
            self.bottomView.frame = CGRectMake(0, kScreenHeigth - 45, kScreenWidth, 45);
        }];
    }];

上傳時報錯:Error ITMS-90635 - Invalid Mach-O in bundle - submitting to App store

CocoPods匯入的框架bitCode不一致導致的,解決方案是在Podfile後面加上

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

然後 pod install --no-repo-update

如果 pod install 報錯,報錯如下:
[!] Invalid Podfile file: syntax error, unexpected tCONSTANT, expecting end-of-input

...ig.build_settings['OTHER_CFLAGS'] || ['$(inherited)']

... ^. Updating CocoaPods might fix the issue.

那就需要先刪除之前Podfile裡面加的post_install do |installer|...... ,然後pod update, 在update之前記得給第三方框架指定一個版本(某些框架最新的可能在你專案無法使用,出現bug),升級後再次執行上面的步驟

podfile示例:

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'AutoPartsStore' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

pod 'AFNetworking', '~>2.4.0'
pod 'Alamofire', '~>3.2.1'
pod 'YYModel', '~>1.0.4'
pod 'Kingfisher', '~>2.1.0'
pod 'MJRefresh', '~>3.1.12'
pod 'SnapKit','~>0.22.0'
pod 'Reachability', '~>3.2'
pod 'MBProgressHUD', '~>1.0.0'

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ENABLE_BITCODE'] = 'NO'
        end
    end
end

  # Pods for AutoPartsStore

end

相關文章