现在iOS开发大都是arc,但是有些地方需要注意,例如KVO,在你注册属性观察者后,也需要在界面释放时注销。
不提其他,仅仅看看tableView中,因为tableViewCell的重用机制,如果在
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中注册,那么就会出现重复注册,最后也就不知道有该如何释放了。
应该在
- (void)tableView:(UITableView *)tableView willDisplayCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath
中注册KVO
那么,我们就应该在
在- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath
中removeObserver。
有一个用RAC再MVVM中做的小玩意。
自己做下笔记,也不做宣传。但是转载请标明出处。
https://github.com/chunnilzp/Rac-.git
https://github.com/chunnilzp/Rac-.git