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

2017-03-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;
}
上一篇 下一篇

猜你喜欢

热点阅读