kysonyangs

Stay Hungry, Stay Foolish


  • 首页

  • 标签

  • 分类

  • 归档

  • 关于

  • 搜索

iOS数组排序

发表于 2015-10-24 | 更新于 2018-11-05 | 阅读次数:

iOS 数组排序

现在有下列两个数组,我们从他们开始接触数组的排序

1
2
NSArray *arrayString = @[@"20", @"30", @"8", @"10", @"9", @"88", @"66"];
NSArray *arrayNumber = @[@20, @30, @8, @10, @9, @88, @66];

1、sortedArrayUsingSelector

这个方法很简单,使用也很便捷,它返回一个排好序的数组

[arrayString sortedArrayUsingSelector:@selector(compare:)];

但是当你执行打印会发现arrayString执行该方法排序后的结果是下图

阅读全文 »

iOS技巧

发表于 2015-10-06 | 更新于 2018-11-05 | 阅读次数:

判断iPhoneX++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
static inline BOOL isIPhoneXSeries() {
BOOL iPhoneXSeries = NO;
if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
return iPhoneXSeries;
}

if (@available(iOS 11.0, *)) {
UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
if (mainWindow.safeAreaInsets.bottom > 0.0) {
iPhoneXSeries = YES;
}
}

return iPhoneXSeries;
}
阅读全文 »

Bug收集

发表于 2015-10-01 | 更新于 2020-05-17 | 阅读次数:

CocoaPods Bug

Use the $(inherited) flag

1
2
3
4
5
6
7
[!] The `MBPeopleBaseApp [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-MBPeopleBaseApp/Pods-MBPeopleBaseApp.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

[!] The `MBPeopleBaseApp [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods-MBPeopleBaseApp/Pods-MBPeopleBaseApp.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

解决方法:

1
Other link flag 添加 $(inherited)

Xcode Bug

自定义的代码片段存放位置

1
~/Library/Developer/Xcode/UserData/CodeSnippets

Xcode 10 Multiple commands produce 报错解决

1
target > Build phase > Copy Bundle Resource/Compile Sources,删掉第三方库中重复的 README.txt,LICENSE,Info.plist 文件

工程文件乱序

选中要整理的文件夹右键,点一下“Sort by Name”或者“Sort by Type”即可排序。

项目打不开 Failed to load project at ‘’ “,incompatible project version

打开 project.pbxproj 文件,修改 objectVersion = 48; 不知道填什么往低了填,或者在自己想买找

Xcode 不高亮

1
2
3
cd Library/Developer/Xcode/DerivedData
rm -rf ./*
重新打开XCODE

打开Playground提示打开失败,找不到合适的devices

1
2
3
1. Quit Xcode
2. Delete the folder /Users/<username>/Library/Developer/CoreSimulator/Devices. For example, in Terminal: rm -rf ~/Library/Developer/CoreSimulator/Devices
3. In Terminal: killall -9 com.apple.CoreSimulator.CoreSimulatorService (or just reboot). OR Add a iOS8.0Device

碰到Xib加载不出来,什么什么工程文件找不到,请看看引用有没有,没有的话加上就好了!

用Xcode 7.3打开一个Xcode 8创建的工程,编译时报错:xxx.storyboard(或者xxx.xib) The document “null” required Xcode 8.0 or later.点击xxx.storyboard(或者xxx.xib)时,弹出如图所示提示框。

解决方法是以源码的方式打开xxx.storyboard(或者xxx.xib),然后删除<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>这一行代码,就OK了。

程序报错

No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=armv7 armv7s)

build 这个target的时候命令行报错。可以在 build setting 中,搜索bitcode,并吧 enable bitcode 设置为 NO.

CopyPngFile Error 报错

TARGETS -> Build Phases -> Copy Bundle Resources -> 删除灰色或红色的文件

Cannot find interface declaration for ‘xxxxViewController’, superclass of ‘xxxViewController’; did you mean ‘UIViewController’

这是因为 父类总出现了交叉引用 前去父类查看 然后改掉就好了

pathForResource nil的情况,而项目命名有该资源

可能没拷贝进bundle

1
Xcode -> TARAGETS -> Build Phases -> Copy Bundle Resources -> 添加

‘Could not instantiate class named xxx’

比如 ‘Could not instantiate class named WKWebView’

解决方法

1
Xcode -> TARAGETS -> General -> Linked Frameworks and Librarier ,点击“+”号添加相应的系统库 webkit.framework

添加新字体, info.plist也配置好了,就是无效

请检查 TARGETS -> Build Phases -> Copy Bundle Resources 中是否添加此资源 其他添加资源后无效也可参考此条解决方案

ld: library not found for -lxxx:

类似出现上面这种问题(我的问题出现在libWeChatSDK这个包) ld:library not found for -lXXX 的问题有可能是你的某个库的连接引用有问题, —–解决的办法就是在项目的target里,选中Link Binary With Libraries 里的.a或framework 取消再加入,就可以了 —–如果是拖拽进入工程的,那就删除,在拖一次.

ld: symbol(s) not found for architecture x86_64

依赖库未导入

tableview遇到这种报错failed to obtain a cell from its dataSource

是因为你的cell被调用的早了。先循环使用了cell,后又创建cell。顺序错了 可能原因:

  1. xib的cell没有注册
  2. 内存中已经有这个cell的缓存了(也就是说通过你的cellId找到的cell并不是你想要的类型),这时候需要改下cell的标识

UIView-Encapsulated-Layout-Width 错误

修改约束优先级即可解决

Swift 创建控制器时自带xib加载在iOS8崩溃的问题

项目中有部分跟随控制器一起创建出来的xib,在iOS8之外的系统运行正常,在iOS8下崩溃,找不到对应关系,一番网上搜索,终于找到解决办法

1
2
3
4
5
6
7
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: "AddressViewController", bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

原来在iOS8下,也需要给控制器的xib重写一下init 方法,只记得在自定义view的是时候用过,没想到这里也需要,特意加上,算是兼容手机系统

ios开发中,xib加载view,loadNibNamed方法奔溃原因之一

xib中某一属性在代码中已删除,但在xib中没有解除关联

-[__NSArray0 addObject:]: unrecognized selector sent to instance 0x7f8a40d039a0

造成原因是你使用[NSArray addObject],而不是[NSMutabeArray addObject];

阅读全文 »

警告收集

发表于 2015-10-01 | 更新于 2020-05-17 | 阅读次数:

消除警告

  1. 使用cocoapods管理的第三方库的警告,直接在podfile文件里面加入 inhibit_all_warnings!
  2. 加入预编译指令:
    1
    2
    3
    4
    5
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    //这里是会报警告的代码
    UIAlertView *alert = [[UIAlertView alloc] initWithFrame:self.view.bounds];
    #pragma clang diagnostic pop

其中:-Wdeprecated-declarations 表示这里有废除,不支持的代码(UIAlertView在2.0-9.0,9.0以上弃用,所以会有警告)

阅读全文 »
1…56

kysonyangs

kysonyangs个人站,备忘

54 日志
13 标签
GitHub
© 2015 — 2020 kysonyangs
由 Hexo 强力驱动 v3.7.1
|
主题 — NexT.Mist v6.3.0