iOS bug整理

bug 1:  自定义控件中 delegate属性, 懒加载代码中, dealloc时

      Cannot form weak reference to instance (0x100450290) of class HZFeedBackController.

      It is possible that this object was over-released, or is in the process of deallocation.

场景:

  自定义控件的代理 @property (weak, nonatomic) id<xxxxDelegate> delegate 属性。

  控制器中 使用懒加载 某控件,并在懒加载中 xx.delegate = self;

  然后该控制器并没有添加该自定义控件。 此时 在 dealloc方法中,对该控件进行的所有操作,都会导致该bug.

    HZFeedBackController 是一个UIViewController;

    LQAlertView 是一个自定义控件,继承UIView。

    在HZFeedBackController 中,有一个 LQAlertView类型的 成员变量 alertV; 

// 懒加载 alertV
- (LQAlertView *)alertV {
    if (_alertV == nil) {
        _alertV = [LQAlertView alertViewWithTip:@"提交成功" image:@"yj_NO1"];
        _alertV.frame = self.view.frame;
        _alertV.delegate = self; // 这里报错
    }
    return _alertV;
}
-(void)dealloc {
    // 当本控制器销毁的时候,移除掉添加在本控制器上的提示框
    [self.alertV removeFromSuperview];
}
 

 解决方式:

  根本原因就是虽然控制器内封装了该空间的懒加载,但是并没有执行该段代码。

   1. 在 dealloc之前的 声明周期方法内引用下 懒加载 代码即可解决该bug。(懒加载就没有意义了)

   2.  还有一种方式就是把代理的设置,放到真正引用该控件以后,也可以解决这个bug。 (推荐这种)

 

 

遇到的问题 之一: 使用xib创建一个tableViewController,默认不支持滚动,必须设置足够多的cell, 或者cell的高度大于当前屏幕显示范围,才能滚动

  尚未解决。想着从xib中创建的tableviewcontroller就能滚动。

  新发现: 在 iOS 9.3中是可以滚动的。 在iOS 10.3中就不可议。

 

bug 2 setion中只有1个row的tableView ,在deleteRow时,发生的错误

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.8.1/UITableView.m:1721

利用每个section中只有一个row,来达成的cell间有间隔效果时候,在row的删除中,执行下列代码会抛出该错误。

[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

  原因: 因为每一个section只有一行,所以不能用删除row,而要用 删除section

 [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];

 

遇到的问题 之二: 使用xib创建一个ViewController, xib中 控件的先后顺序,会对页面显示有影响。

  页面问题定位不到的时候,要注意xib中 控件的先后顺序。

posted @ 2017-08-10 09:35  Anastatica  阅读(152)  评论(0编辑  收藏  举报