作为IOS开发初学者,该博客用于记录学习过程中遇到的问题。
解决bug的方法或来自网络,或依据个人理解。由于水平局限性,可能分析问题过于表面,深层次的原理不甚了解。若有高手路过,请指教。当然,文中出现的错误,也请指出,感激不尽。
一
在Source Text Field中不小心勾选了Font(Share User…),导致图中错误:
错误信息
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Cannot create NSFont from object <_NSControllerObjectProxy: 0x6000000046f0> of class _NSControllerObjectProxy’
terminating with uncaught exception of type NSException
错误原因
IB文件中记录了关联信息,但是代码中却没有相关变量和方法。
解决办法
按照需求,删除IB文件中的关联或是在代码中添加缺损内容。
二
问题描述
点击UIScrollView的子view时,view向上发生了移动。
原因分析
系统默认会在addsubview之后,就是scrollView展示之前自动的调整Inset,导致了offset的变化,所以初始化的时候,其实整体的页面是下移的。设置了pagingEnabled,系统会自动的处理offset来实现分页的效果.所以对于垂直方向,所以这种自动处理在滑动时会导致之前变化的offset回滚到0。所以就有了上移,而不设置pagingEnabled时系统不会自动调整offset,完全由用户操作,所以就不会出现这种现象。
引自网课老师解答:https://time.geekbang.org/course/detail/100025901-93959
解决办法
设置scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever。在开发过程中的frame布局的项目中,所有的scrollView也都建议设置这个属性。
三
问题描述
在使用第三方网络库AFNetWorking(4.0.1)时,利用HTTP协议请求数据,发生错误。
代码:
NSString *urlString = @"http://v.juhe.cn/";
// use AFNetWorking
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:urlString parameters:nil headers:nil progress:^(NSProgress * _Nonnull downloadProgress) {
NSLog(@"download.");
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"success.");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"failure.");
}];
输出:
2021-04-21 10:53:31.479709+0800 02_SampleApp[11689:624435]
2021-04-21 10:53:31.511928+0800 02_SampleApp[11689:624555] download.
(lldb) po error
Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={NSLocalizedDescription=Request failed: unacceptable content-type: text/html, NSErrorFailingURLKey=http://v.juhe.cn/, com.alamofire.serialization.response.error.data={length = 221, bytes = 0x3c21444f 43545950 45204854 4d4c2050 ... 0a3c2f68 746d6c3e }, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x60000230a800> { URL: http://v.juhe.cn/ } { Status Code: 200, Headers {
"Accept-Ranges" = (
bytes
);
Connection = (
"keep-alive"
);
"Content-Length" = (
221
);
"Content-Type" = (
"text/html"
);
Date = (
"Wed, 21 Apr 2021 02:53:28 GMT"
);
Etag = (
"\"57a19bb8-dd\""
);
"Keep-Alive" = (
"timeout=4"
);
"Last-Modified" = (
"Wed, 03 Aug 2016 07:22:32 GMT"
);
"Proxy-Connection" = (
"keep-alive"
);
"Set-Cookie" = (
"aliyungf_tc=9c71651fa7cadf4348b67367d76372623f120562414153de5ff689243d149ed6; Path=/; HttpOnly"
);
} }}
2021-04-21 10:58:22.853859+0800 02_SampleApp[11689:624435] failure.
(lldb)
在不改变库源码的前提下,尝试了网上相关博客方法均不能完美解决,留作后续研究,若有大神指导,不胜感激
将URL修改为:
NSString *urlString = @"http://v.juhe.cn/toutiao/index?type=top&key=97ad001bfcc2082e2eeaf798bad3d54e";
问题没有出现,输出:success.