iOS 遇到的一些问题
来源:互联网 发布:有谁在医院做网络咨询 编辑:程序博客网 时间:2024/06/06 13:07
1.EXC BAD ACCESS 野指针
2. whose view is not in the window hierarchy! 在viewDidLoad中使用了presentViewController
解决方法:延迟调用
3.UITABLEVIEW重用错误(原因未知问题出现在iphone6之前)
分组1为头像,分组2为普通图标加文字
单元格超出屏幕,往下拉时出现如图所示,单元格冲突的情况。
解决方案
分组1和分组2使用不同的identifier
4.给UILabel添加text的时候,如果出现数据格式错误,则会报错(unrecognized selector sent to instance 0xb000156071cf3283)
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key uploadState
这种问题有可能是由于缓存未清除造成的
5.打包的version问题:首先version不能包含字符,当然也不能出现空格
6.关于ATS的问题:当使用Allow Arbitrary Loads为yes的时候可以使用网络请求,但需要在2017年之后更改,当添加Allow Arbitrary Loads in Web Content 的时候UIImageView无法加载网络图片的问题
7.UITableView 风格为plain的时候,如果单元格不够铺满页面,就会自动分行出多个单元格,但使用group风格即可避免这个问题,但必须设置分组头和尾的高度。
8.cocoapod ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解决方法: sudo gem install -n /usr/local/bin cocoapods
9.关于iOS的编译指令集
目前iOS的指令集有以下几种:
- armv6
- iPhone
- iPhone2
- iPhone3G
- 第一代和第二代iPod Touch
- armv7
- iPhone4
- iPhone4S
- armv7s
- iPhone5
- iPhone5C
- arm64
- iPhone5S
- iPhone6
- ......
机器对指令集的支持是向下兼容的,因此armv7的指令集是可以运行在iphone5S的,只是效率没那么高而已~
================================================
Architecture : 指你想支持的指令集。
Valid architectures : 指即将编译的指令集。
Build Active Architecture Only : 只是否只编译当前适用的指令集。
================================================
现在是2014年初,其实4和4S的用户还是蛮多的,而iphone3之类的机器几乎没有了,所以我们的指令集最低必须基于armv7.
因此,Architecture的值选择:armv7 armv7s arm64
PS:选arm64时需要最低支持5.1.1:
1,如果想自己的app在各个机器都能够最高效率的运行,则需要将Build Active Architecture Only改为NO,Valid architectures选择对应的指令集:armv7 armv7s arm64。这个会为各个指令集编译对应的代码,因此最后的 ipa体积基本翻了3倍,Release版本必须NO。
2,如果想让app体积保持最小,则现阶段应该选择Valid architectures为armv7,这样Build Active Architecture Only选YES或NO就无所谓了
10.一段面试代码
OBJC_EXPORTvoid objc_msgSendSuper(void/* struct objc_super *super, SEL op, ... */
)
/// Specifies the superclass of an instance.
struct
objc_super {
/// Specifies an instance of a class.
__unsafe_unretainedid
receiver;
/// Specifies the particular superclass of the instance to message.
#if !defined(__cplusplus) && !__OBJC2__ /* For compatibility with old objc-runtime.h header */
__unsafe_unretainedClass class;#else __unsafe_unretained Class super_class;#endif /* super_class is the first class to search */
代码解释
@implementation
Son : Father
- (
id
)init
{
self = [super
init];
if (self
)
{
NSLog(@"%@", NSStringFromClass([self
class]));
NSLog(@"%@", NSStringFromClass([super
class]));
}
return self
;
}
@end
11.ios自动生成123倍图片
选择Type,有位图和矢量图,选择矢量图,让美工切一个@1x的PDF格式的矢量图拖进去,运行的时候会自动生成@1x,@2x,@3x的图片。
12.对属性采用copy的时候将会走copyWithZone方法
@property(nonatomic,copy)id<JHActionSheetDelegate>JHdelegate;
13.在xib中加载顺序为
- (void)awakeFromNib
-(void)layoutSubviews
-(void)drawRect:(CGRect)rect
那么若想要获取UIImageview大小并设置layer使它成为圆形则需要
self.PortraitImage.layer.cornerRadius= self.PortraitImage.frame.size.width/2;
且在
-(void)drawRect:(CGRect)rect中才会有效果,否则获取到的frame并不是真实的大小,而是xib控件绘制时候的大小
14.Xcode忽略警告的做法
#pragma clang diagnostic push
#pragma clang diagnostic ignored
"-Wunused-variable"
NSInteger s = 666;
#pragma clang diagnostic pop
15.UITextView自动偏移的解决
当UITextView输入到两行的时候,再清空文字,这时候会发生输入文字的偏移,原因为,系统自动改变了textContainer的frame,也就是textView的contentSIze
解决方案
-(void)textViewDidChange:(UITextView
*)textView{
//由于清空的时候出现偏移的bug,故这里手动设置容器大小
if (textView.text.length==0
) {
_textView.contentSize = CGSizeMake(_textView.frame.size.width, _textView.frame.size.height
);
}
}
16.[!] The 'Pods-掌上行车' target has libraries with conflicting names: libcrypto.a and libssl.a.
原因为网易云信和百度mapKit引用OpenSSL冲突,有可能原因为cocoaPod版本太高,将其版本降低至1.0.1即可
17.PHAsset类获取Data数据
PHVideoRequestOptions*options = [[PHVideoRequestOptionsalloc]init];
options.version= PHImageRequestOptionsVersionCurrent;
options.deliveryMode= PHVideoRequestOptionsDeliveryModeAutomatic;
PHImageManager *manager = [PHImageManagerdefaultManager];
[managerrequestAVAssetForVideo:assetoptions:optionsresultHandler:^(AVAsset* _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
AVURLAsset *urlAsset = (AVURLAsset*)asset;
NSURL *url = urlAsset.URL;
NSData *data = [NSDatadataWithContentsOfURL:url];
//获取windows
[[NSOperationQueuemainQueue]addOperationWithBlock:^{
NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windowsreverseObjectEnumerator];
for (UIWindow*windowin frontToBackWindows)
{
BOOL windowOnMainScreen = window.screen== UIScreen.mainScreen;
BOOL windowIsVisible = !window.hidden&& window.alpha> 0;
BOOL windowLevelNormal = window.windowLevel== UIWindowLevelNormal;
if(windowOnMainScreen && windowIsVisible && windowLevelNormal)
{
[windowaddSubview:self];
break;
}
}
}];
18.//播放声音的时候,由于播放的是第二个音频,受到前一个的影响,故改变AVAudioSessionCategoryPlayback,然而这时候话筒是无法使用的,故在播放结束的代理中AVAudioSessionCategoryPlayAndRecord
//铃声- 接听播放铃声
- (void)playStartRing{
//在前面加上
AVAudioSession *audioSession = [AVAudioSessionsharedInstance];
NSError *err = nil;
[audioSessionsetCategory :AVAudioSessionCategoryPlaybackerror:&err];
[self.playerstop];
// self.player = nil;
NSString *path = [[NSBundlemainBundle]pathForResource:@"icbc"ofType:@"mp3"];
NSURL *url = [NSURLfileURLWithPath:path];
self.player= [[AVAudioPlayeralloc]initWithContentsOfURL:urlerror:nil];
//循环次数
self.player.numberOfLoops= 0;
// self.player.volume = 1.0;
[self.playerplay];
self.player.delegate= self;
}
/**
监听播放器完成,改变AVAudioSession输入类型。否则无法输入话筒
*/
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer*)player successfully:(BOOL)flag{
//在前面加上
AVAudioSession *audioSession = [AVAudioSessionsharedInstance];
NSError *err = nil;
[audioSessionsetCategory :AVAudioSessionCategoryPlayAndRecorderror:&err];
}
19.一个静止长按动作的输入框
/**
一个静止长按动作的输入框
*/
@interfaceJHWithoutActionText :UITextField
@implementationJHWithoutActionText
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
UIMenuController*menuController = [UIMenuControllersharedMenuController];
if(menuController) {
[UIMenuControllersharedMenuController].menuVisible=NO;
}
return NO;
}
//- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
//{
// if (action == @selector(paste:))//禁止粘贴
// return NO;
// if (action == @selector(select:))//禁止选择
// return NO;
// if (action == @selector(selectAll:))//禁止全选
// return NO;
// return [super canPerformAction:action withSender:sender];
//}
20.大位数计算使用NSDecimalNumber,否则会出现精确地失常
21.WKWebView加载html源码出现的字体大小不一致解决方法
/**
* 如果是含有html源码,将直接加载html源码
*/
if (![self.tplisKindOfClass:[NSNullclass]]&&self.tpl!=nil) {
NSString *headerString = @"<header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'></header>";
[self.webViewloadHTMLString:[headerStringstringByAppendingString:_tpl]baseURL:nil];
}
阅读全文
0 0
- iOS遇到的一些问题
- iOS 遇到的一些问题
- ios打包遇到的一些小问题
- ios中最近遇到的一些问题
- ios开发遇到的一些问题0228
- ios 开发中遇到的一些问题
- iOS - 开发者遇到的一些小问题
- ios afnetworking https遇到的一些问题
- IOS的图标设置以及遇到的一些问题
- ios移动开发遇到的一些小问题的解决办法
- 遇到的一些问题
- 遇到的一些问题
- 遇到的一些问题
- 遇到的一些问题
- 遇到的一些问题
- 我在ios游戏开发中遇到的一些问题
- 记录 cocos2dx ios&android遇到的一些注意问题
- 记录 cocos2dx ios&android遇到的一些注意问题
- 最新最全的阿里云产品手册出炉
- floating ip
- IOC模式理解
- webpack 学习指南
- Jmeter中的几个重要测试指标释义
- iOS 遇到的一些问题
- mysql5.7用户管理:添加用户、授权、撤权、修改密码
- 关于升级Android Studio后部分报错信息笔记
- js 正则 判断金额
- 文章标题
- 使用matlab生成rom初始化文件.coe
- React Router Examples
- 简单的长方形进度条
- 版本控制-Git常用命令