iOS 常见问题集锦(一)

1:AlertView cancle pop后键盘弹出

A push B, B 点返回的时候弹出AlertView(B中有个输入框之类的),点击取消,pop到A。返回A后键盘会出现,再做动画返回。
原因:alertview关闭影响了系统其他的动画导致。
解决办法:要么延迟调用(延迟0.25秒,键盘动画收回的时间),在pop;要么自己做一个alertview。

2:UIWebView占内存过大

WKWebView新特性:
在性能、稳定性、功能方面有很大提升(最直观的体现就是加载网页是占用的内存,模拟器加载百度与开源中国网站时,WKWebView占用23M,而UIWebView占用85M).

3:如何设置虚线描边

 self.border = [CAShapeLayer layer];
 _border.strokeColor = kMainColor.CGColor;
 _border.fillColor = nil;
 _border.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.height / 2].CGPath;
 _border.frame = self.bounds;
 _border.lineWidth = 0.5f;
 _border.lineCap = @"square";
 _border.lineDashPattern = @[@3, @3];

 [self.layer addSublayer:_border];

4:如何获取光标位置

int location = aTextView.selectedRange.location;

5:UIScrollView加载子视图偏移64的问题

在一个VC里如果第一个控件是UIScrollView,注意是第一个控件,就是首先addsubview在VC.view上。接着加到scrollView上的View就会在Y点上发生64的偏移(也就是navigationBar的高度44+电池条的高度20)。
这个在iOS7以后才会出现。

解决办法:

self.automaticallyAdjustsScrollViewInsets = false; 

6:自定义leftBarButtonItem右划返回无效

关于右划返回上一级自定义leftBarButtonItem后无法启用系统自带的右划返回可以再设置以下代码
self.navigationController.interactivePopGestureRecognizer.delegate = self;

7: 去掉导航栏下边的黑线

[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

8:忽略警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self performSelector:example.selector];
#pragma clang diagnostic pop

9:UITableView隐藏多余的分隔线

设置tableViewFooter即可

self.sampTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

10:SVN怎么查看最近log信息

svn log | head -n X
x代表行数

11:SVN怎么查看指定日期的log信息

svn log -r {2016-4-24}:{2016-4-26} -v
开始日期:结束日期
-v 打印详细信息 和svn log --verbose 中 --verbose一样的效果

12:UIActionSheet代理present UIImagePickerController异常

在UIActionSheetDelegate代理方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

present UIImagePickerController时报警告:

Warning: Attempt to present  on 
<**Controller: 0x> which is already presenting 

这是因为已经有actionSheet存在了,不能present新的。
解决:把present代码换个代理方法里面实现:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 

13:关于const定义常量的问题

static NSString const * kUserName = @"Strong";
static const NSString * kUserName = @"Strong";

如上定义这个kUserName其实是可以更改的。下面的代码kUserName才是不可变的

static NSString * const kUserName = @"Strong";

当const修饰的是(*****kUserName)的时候,不可变的是*****kUserName;
星号*在C语言中表示指针指向符,也就是说这个时候*****userName指向的内存地址中的内容不可变,而kUserName这个指针是可变的。
总结: const 修饰的是他右边的部分

14:Xcode的运行环境没有模拟器了

原因1:Xcode没有下载模拟器;
解决:用command + , 快捷键打开偏好设置,选择downloads选项,下载模拟器即可。
原因2:新建的工程默认的Deployment Target是8.4,模拟器没有8.4或者比8.4更高的了。所以无法选择模拟器了;
解决:把模拟器的运行环境往下降就好了。

15: 计算NSData大小

- (NSString *)getFileSizeByBt:(NSNumber *)fileSize {
    CGFloat size = [fileSize floatValue];
    if (size >= 1024*1024*1024) {
        return [NSString stringWithFormat:@"%.2fG",size/(1024*1024*1024)];
    }else if (size >= 1024*1024) {
        return [NSString stringWithFormat:@"%.2fM",size/(1024*1024)];
    }else{
        return [NSString stringWithFormat:@"%.2fK",size/1024];
    }
}

16:如何清除xcode里面的Provisioning Profiles

终端:

cd ~/Library/MobileDevice/Provisioning Profiles/
rm  *.mobileprovision

手动 : 资源库->MovileDevice->provisioning Profiles->目的文件

iOS 常见问题集锦(一)_第1张图片
deleteProvisioningProfiles.png

17:字符串中去除特殊符号

NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、[]{}#%-*+=_\\|~<>$€^•'@#$%^&*()_+'\""];
NSString *trimmedString = [string stringByTrimmingCharactersInSet:set];

18:app在后台或者没启动的时候,收到远程通知badge不显示

app在后台和没启动的时候,应用图标右上角的数字图标是根据远程通知里面数据来显示的,控制的key就是badge,在aps字典中,badge对应的字段,注意,badge对应的字段必须是数字,不能是字符,如果服务器传给APNS的badge是字符型,那app接受到远程通知的时候,就显示不出来右上角的数字了。

19:怎么改变textField的placeholder字体颜色和大小

使用KVC找到placeholderLabel,对齐属性赋值

[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

20:消除导航条返回键带的title

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
  forBarMetrics:UIBarMetricsDefault];

21:将Navigationbar变成透明而不模糊

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                         forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar .shadowImage = [UIImage new];
self.navigationController.navigationBar .translucent = YES;

22:加载bundle中的图片

_iconImageView.image = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"UMSocialSDKResourcesNew.bundle/SnsPlatform/[email protected]"]];

你可能感兴趣的:(iOS 常见问题集锦(一))