美文网首页
iOS-36-关于UI控件创建时候的死循环

iOS-36-关于UI控件创建时候的死循环

作者: 小东门儿 | 来源:发表于2017-03-02 16:02 被阅读138次

今天中午做页面的时候遇到个恶心的问题,该操作本来是为了避免该控件重复创建的,俗称懒加载。但是在实际运行中会在

UITableView* cityTable = [[UITableView alloc] init];

[self addSubview:cityTable];

之间一直重复循环,最终报死。不明所以。

- (UITableView*)cityTable
{
    if (!_cityTable) {
        UITableView* cityTable = [[UITableView alloc] init];
        cityTable.frame = CGRectMake(0, 0, ScreenWidth / 3, 200);
        cityTable.delegate = self;
        cityTable.dataSource = self;
        cityTable.backgroundColor = UIColorFromRGB(0xf2f2f2);
        cityTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self addSubview:cityTable];
        _cityTable = cityTable;
    }
    return _cityTable;
}

相关文章

网友评论

      本文标题:iOS-36-关于UI控件创建时候的死循环

      本文链接:https://www.haomeiwen.com/subject/dvkcgttx.html