iOS常见问题解决方案(长期更新)

整理时间:2017年05月02日12:06:17

1. 解决XCode 8.1 的bundle format unrecognized, invalid, or unsuitable的问题

注意一般是在 CocoaPods中使用出现的问题

解决方案:

  • 首先选中Pods下你的目标工程

  • 找到General选项卡

  • 在General选项卡下找到Identity

  • 选择Choose info.plist然后进行导入

  • 接着执行Product Clean

2.解决tableView分割线,不能触及最左边的屏幕

注意如果不做额外处理,分割线默认是不会触及左边缘的,这个是苹果内置api决定的

解决方案:实现如下方法


// 这里面的_cofTableView,是我创建的tableView

#pragma mark - tableView seprator line cant touch left

- (void)viewDidLayoutSubviews 
{

if ([_cofTableView respondsToSelector:@selector(setSeparatorInset:)]) {

[_cofTableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];

}

if ([_cofTableView respondsToSelector:@selector(setLayoutMargins:)]) {

[_cofTableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];

}

}

#pragma mark - tableView delegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{

if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {

[cell setSeparatorInset:UIEdgeInsetsZero];

}

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

[cell setLayoutMargins:UIEdgeInsetsZero];

}

}

3.解决横竖屏切换,宽高数值不正确

解决方案:


#pragma mark - orientation private method

// 添加屏幕旋转监听

- (void)addObserver 
{

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];

}

// 处理屏幕旋转事件

- (void)deviceOrientationDidChange 
{

UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;

if(orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {

_cofTableView.frame = CGRectMake(0, 0, kScreenW, kScreenH);

} else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight ) {

_cofTableView.frame = CGRectMake(0, 0, kScreenW, kScreenH);

}

}

// 是否支持屏幕旋转

- (BOOL)shouldAutorotate 
{

return NO;

}

4.解决放在资源Document目录下,会被iTunes同步的问题


+ (BOOL)addSkipBackupAttributeToItemAtPath:(NSString*)filePathString 
{

// 获取文件路径

NSURL *URL= [NSURL fileURLWithPath: filePathString];

assert([[NSFileManager defaultManager] fileExistsAtPath:[URL path]]);

NSError *error = nil;

BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];

if(!success) {

NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);

}

return success;

}

5.解决Undefined symbols for architecture armv7: “_objc_readClassPair”, referenced from: __ARCLite__load() in libarclite_iphoneos.a(arclite.o)

在build settings关闭 "Implicitly Link Objective-C Runtime Support"

6. 解决CocoaPods导入第三方库,提示找不到头文件

1. 找到TARGETS -> Build Settings -> SearchPaths -> User Header Search Paths  在后面的空白处双击
2.点击 '+' 号,添加一个新的键为${SRCROOT},值设置为recursive
3.Product -> Clean

7.iOS8以上白色状态栏

状态栏的字体为黑色:UIStatusBarStyleDefault
状态栏的字体为白色:UIStatusBarStyleLightContent

全局修改:
在info中设置Status bar style为UIStatusBarStyleDefault或
UIStatusBarStyleLightContent(默认UIStatusBarStyleDefault)
将View controller-based status bar appearance设为NO。
如果View controller-based status bar appearance为YES, 则Status bar style设置无效。

8.iOS9 & iOS10 HTTP 不能正常使用的解决办法

在Info.plist中添加NSAppTransportSecurity类型Dictionary。
在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES

9.强制退出app

#pragma mark - 强制退出功能
- (void)exitApplication
{
    [UIView beginAnimations:@"exitApplication" context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.window cache:NO];
    [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
    self.window.bounds = CGRectMake(0, 0, 0, 0);
    [UIView commitAnimations];
}

- (void)animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    if ([animationID compare:@"exitApplication"] == 0)
    {
        exit(0);
    }
}

你可能感兴趣的:(iOS常见问题解决方案(长期更新))