原文链接:http://www.jianshu.com/p/11bc11a00f7f
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
一.Unknown class XXX in Interface Builder file
1.错误出现后的现象:
(1)例如第一次是自定义的 CornerButton 文件没有找到 导致所有界面中用到 这个试图的 button 都没能正确的变为圆角,但是编译不会出错 (打印信息1)
(2)再次出现是在 一个 XXXViewController 导致的结果是 编译不会报错,但是当点击到跳转该界面是会 崩溃,并且报错信息为 一个动态库的错误 “libc++abi.dylib: terminating with uncaught exception of type NSException”(如图 崩溃信息1)<勘误1>
2.解决办法
到 project -> targets -> build phasses -> compile Sources 中添加所报的 unknown class... 例如 添加 CornerButton.m 文件(如图 解决办法1)
补充:Undefined symbols for architecturei386:(或者x8_64:) 如果缺少类库,则在Link Binary With Libraries中加入该类库。
二.CGContextSetStrokeColorWithColor: invalid context 0x0.
1.报错名称 : CGContextSaveGState: invalid context 0x0. CGContextDrawPath: invalid context 0x0.等。我这里编译时并没有报错也无警告,直到运行时才在控制台打印了一系列的<Error>信息 如下图(错误信息)
出现这类错误的原因是没有在 view 的 -drawRect: 方法中对 layer 进行了不适当的操作 例如 UIBezierPath 的 - (void)setFill; - (void)setStroke; 方法 UIColor 的 - (void)setFill; - (void)setStroke;方法 等。
2.解决方法
(1).把有关于 view layer 层的操作单独封装到一个 view 类的 -drawRect: 方法中
(2).不要调用 相关的方法 ,官方一般都给了注释,com+单击 就可查看:如下图(官方给定的限制->drawing context)
勘误:
1.并不是所有缺少 XXXViewController 都会在跳转的时候导致崩溃,但是如果 这个VC有关联的sb或者xib文件时一定会崩溃。如下图(勘误1)是 Unknown class ViewController1 in Interface Builder file 时,ViewController1 中的关联失效
三.关于xib或者SB中的两个警告的问题(在兼容iOS6.0时出现)
3.1.1 警告及原因: Automatic Preferred Max Layout Width before iOS 8.0 (或者是:Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0 。具体警告应该和 XCode版本有关,我的是XCode7.1正式版的),警告出现在‘UILabel’的约束中,出现次警告的设置如下图
3.1.2 解决办法:如下图设置
解释:1.为什么会填入300? 这是因为我设置的 约束为 距离屏幕左右各为10的距离 然后考虑到,运行在iPhone4s 上 因此 设为 屏幕的宽320 减去 边距 10 ,10
2.Preferred Width(自动换行最大宽度) 设置为300 会不会影响在 6和6p上的换行?不会的 运行效果如下图,只有在到达约束的限制距离时 才会启动换行
3.2 'Jusitfied or Natural text alignment before iOS 7.0'
出现的警告原因已经很明确了,对 ‘UILabel’ 的 textAligment 的设置不兼容 iOS 7.0 之前的系统,出现的原因如下图:
解决方法:十分简单 ,根据需求选择图中圈中的任意一种对齐方式即可(创建的时候一定要仔细要不你就要和我一样该一中午的sb和xib文件了)
四.集成了某些第三方后突然出现200+的警告(如下)
warning: /Users/qiandong/Library/Developer/Xcode/DerivedData/ModuleCache/OJZ27JBFTDXF/ObjectiveC-1AJ1UYHO2U5H0.pcm: No object file for requested architecture
warning: Could not resolve external type c:objc(cs)NSObject
warning: Could not resolve external type c:objc(cs)NSString
warning: Could not resolve external type c:objc(cs)NSMutableDictionary
等等。。大量的相似警告
解决办法:如下图设置即可
(具体原因:说法好多,也不知道该怎么解释了,可以自己 google )
四."std::__1::__vector_base_common::__throw_length_error() const", referenced from: 等一大堆类此错误
1.报错形式如下
Undefined symbols for architecture x86_64: "std::__1::__vector_base_common::__throw_length_error() const", referenced from: cv::SparseMat::resizeHashTab(unsigned long) in opencv2(matrix.o) std::__1::vector>::__append(unsigned long) in opencv2(matrix.o) std::__1::vector>::__append(unsigned long) in opencv2(matrix.o) std::__1::enable_if<(__is_forward_iterator::value) && (is_constructible::reference>::value), void>::type std::__1::vector>::assign(cv::cuda::GpuMat*, cv::cuda::GpuMat*) in opencv2(matrix.o) std::__1::vector>, std::__1::allocator> > >::__append(unsigned long) in opencv2(matrix.o) std::__1::vector>, std::__1::allocator> > >::__swap_out_circular_buffer(std::__1::__split_buffer>, std::__1::allocator> >&>&) in opencv2(matrix.o) std::__1::vector>::__append(unsigned long) in opencv2(matrix.o) ... "std::__1::__basic_string_common::__throw_length_error() const", referenced from: std::__1::basic_stringbuf, std::__1::allocator>::str() const in opencv2(ocl.o) "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from: std::__1::basic_ostream>& std::__1::__put_character_sequence>(std::__1::basic_ostream>&, char const*, unsigned long) in opencv2(ocl.o) "std::__1::ios_base::getloc() const", referenced from: std::__1::basic_ostream>& std::__1::__put_character_sequence>(std::__1::basic_ostream>&, char const*, unsigned long) in opencv2(ocl.o) "std::__1::basic_string, std::__1::allocator>::resize(unsigned long, char)", referenced from: std::__1::basic_stringbuf, std::__1::allocator>::str(std::__1::basic_string, std::__1::allocator> const&) in opencv2(ocl.o) std::__1::basic_stringbuf, std::__1::allocator>::overflow(int) in opencv2(ocl.o) "std::__1::basic_string, std::__1::allocator>::push_back(char)", referenced from: std::__1::basic_stringbuf, std::__1::allocator>::overflow(int) in opencv2(ocl.o) "std::__1::basic_string, std::__1::allocator>::~basic_string()", referenced from: cv::ocl::kernelToStr(cv::_InputArray const&, int, char const*) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) ... "std::__1::basic_string, std::__1::allocator>::operator=(std::__1::basic_string, std::__1::allocator> const&)", referenced from: std::__1::basic_stringbuf, std::__1::allocator>::str(std::__1::basic_string, std::__1::allocator> const&) in opencv2(ocl.o) "std::__1::basic_ostream>::sentry::sentry(std::__1::basic_ostream>&)", referenced from: std::__1::basic_ostream>& std::__1::__put_character_sequence>(std::__1::basic_ostream>&, char const*, unsigned long) in opencv2(ocl.o) "std::__1::basic_ostream>::sentry::~sentry()", referenced from: std::__1::basic_ostream>& std::__1::__put_character_sequence>(std::__1::basic_ostream>&, char const*, unsigned long) in opencv2(ocl.o) "std::__1::basic_ostream>::~basic_ostream()", referenced from: construction vtable for std::__1::basic_ostream>-in-std::__1::basic_ostringstream, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_ostream>::~basic_ostream()", referenced from: construction vtable for std::__1::basic_ostream>-in-std::__1::basic_ostringstream, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_ostream>::~basic_ostream()", referenced from: std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) ... "std::__1::basic_ostream>::operator<<(double)", referenced from: std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) "std::__1::basic_ostream>::operator<<(float)", referenced from: std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) "std::__1::basic_ostream>::operator<<(int)", referenced from: std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) ... "std::__1::basic_ostream>::operator<<(short)", referenced from: std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) "std::__1::basic_ostream>::operator<<(unsigned short)", referenced from: std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) "std::__1::basic_streambuf>::sync()", referenced from: vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_streambuf>::imbue(std::__1::locale const&)", referenced from: vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_streambuf>::uflow()", referenced from: vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_streambuf>::setbuf(char*, long)", referenced from: vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_streambuf>::xsgetn(char*, long)", referenced from: vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_streambuf>::xsputn(char const*, long)", referenced from: vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_streambuf>::showmanyc()", referenced from: vtable for std::__1::basic_stringbuf, std::__1::allocator> in opencv2(ocl.o) "std::__1::basic_streambuf>::basic_streambuf()", referenced from: std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) ... "std::__1::basic_streambuf>::~basic_streambuf()", referenced from: std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator> cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o) std::__1::basic_string, std::__1::allocator > cv::ocl::kerToStr(cv::Mat const&) in opencv2(ocl.o)ld:
symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation
有这么多的link STL的错误。其实,就是你编译静态库的时候使用不同版本的标准库,C++ Standard Library
类似情况会出现在 c++ 混编的情况下,如下设置可消除报错