iOS Bug 记录

1.问题描述:duplicate symbols for architecture x86_64

duplicate symbols for architecture x86_64                                           

原因:在在建model的时候重复了某个类

2.问题描述:复制整个控制器(xib搭建界面)到另一个项目,控制器内容不显示

原因:勾选上第一个就可以了

3.NSURL urlWithString 得到的对象为null的问题原因以及解决

有些string存在特殊的编码,在转化url之前进行重新编码一下

 iOS9之前:urlString=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

 iOS9之后:urlstring=[urlstring stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

4.dealloc方法不执行

系统不调用dealloc方法网上搜到有以下几个原因:

(1)viewcontroller中存在定时器NSTimer

 [self.timerinvalidate];//结束定时

self.timer =nil;//nil

(2)viewcontroller中有代理Delegate,需要设置delegate的时候,设置为weak

@property (nonatomic,weak)iddelegate;

(3)viewcontroller中有Block方法

block会把它里面的所有对象强引用,包括当前控制器self,因此有可能会出现循环引用的问题。比如viewController中有个block属性,在block中又强引用了self或者其他成员变量,那么这个viewController与自己的block属性就形成循环引用,导致viewController无法释放。

    __weak typeof(self) weakSelf =self;

    [self.tableViewtableViewAddUpLoadRefreshing:^{

[weakSelfloadCommentListData];

    }];

我项目中查明原因是由(3)导致的,值得注意的是以下这个方法:

- (id)addObserverForName:(nullableNSNotificationName)name object:(nullableid)obj queue:(nullableNSOperationQueue *)queue usingBlock:(void(^)(NSNotification *note))block API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0));

    // The return value is retained by the system, and should be held onto by the caller in

    // order to remove the observer with removeObserver: later, to stop observation.


一开始以为这个是和 [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>]一样的,block未被self持有,但是看注释:The return value is retained by the system, and should be held onto by the caller in。所以在block里也要使用弱引用。

5.避免循环引用的坑:在Block中使用私有成员变量  https://www.jianshu.com/p/726c91188e20

WeakSelf

    self.tbV.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{

        __strongtypeof(weakSelf)sself=weakSelf;

        sself->_page+=1;

        [weakSelfloadData];

    }];

6. iOS 提示用self替换_的警告

Building Settings 

CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF=NO

https://stackoverflow.com/questions/21577711/block-implicitly-retains-self-explicitly-mention-self-to-indicate-this-is-i

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容