Giter Site home page Giter Site logo

customnotification's Introduction

CustomNotification


###三个类一个方法模拟iOS通知实现

三个类:

/**
 *  @brief  关于通知的信息类
 */
@interface MyNotification : NSObject

@property (nonatomic, strong, readwrite) NSString *name;

@property (nonatomic, assign, readwrite) id object;

@property (nonatomic, strong, readwrite) NSDictionary *infoDictionary;

- (id)initWithName:(NSString *)name object:(id)anObject userInfo:(NSDictionary *)someUserInfo;

@end
/**
 *  @brief  存储关于注册的观察者的信息
 */
@interface MYNotificationObserverRecord : NSObject

@property (nonatomic, assign, readwrite) id object;

@property (nonatomic, assign, readwrite) id observer;

@property (nonatomic, assign, readwrite) SEL selector;

@end
/**
 *  @brief 单例模式 逻辑处理类
 */
@interface MYNotificationCenter : NSObject

@property (nonatomic, strong) NSMutableDictionary *observersDictionary;

- (id)defaultCenter;

- (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)objectOfInterest;

- (void)removeObserver:(id)notificationObserver;

- (void)postNotification:(MyNotification *)aNotification;

- (void)postNotification:(NSString *)aName object:(id)objectOfInterest userInfo:(NSDictionary *)someUserInfo;

@end

一个方法:

- (id)performSelector:(SEL)aSelector withObject:(id)object;

###注意几点:

1.记得remove!记得remove!记得remove!

2.在接收通知的方法里加一个判断 if (self.isViewLoaded && self.view.window) {}

3.注意线程问题

customnotification's People

Contributors

chaihuoa avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.