吐槽下iOS8[一] notification, scrollview.delegate
NotificationCenter
从iOS 9
开始, 使用NotificationCenter
添加Observer之后, 不在需要自行调用removeObserver:
方法:
- removeObserver:
Removes all entries specifying a given observer from the notification center's dispatch table.
Declaration
- (void)removeObserver:(id)observer;
Parameters
observer
The observer to remove.
Discussion
If your app targets iOS 9.0 and later or macOS 10.11 and later, you don't need to unregister an observer in its dealloc method. Otherwise, you should call this method or removeObserver:name:object: before observer or any object specified in addObserverForName:object:queue:usingBlock: or addObserver:selector:name:object: is deallocated.
You shouldn't use this method to remove all observers from a long-lived object, because your code may not be the only code adding observers that involve the object.
The following example illustrates how to unregister someObserver for all notifications for which it had previously registered. This is safe to do in the dealloc method, but should not otherwise be used (use removeObserver:name:object: instead).
[[NSNotificationCenter defaultCenter] removeObserver:someObserver];
Availability
iOS 2.0+
macOS 10.0+
tvOS 9.0+
watchOS 2.0+
See Also
removeObserver:name:object:
scrollView.delegate
iOS9之前, scrollView的delegate是没有用weak修饰的, 需要手动释放.
//iOS9 以前
@property(nonatomic,unsafe_unretain) id<UIScrollViewDelegate> delegate;
//iOS9
@property(nullable,nonatomic,weak) id<UIScrollViewDelegate> delegate;
这里还有更加详细的说明: