{"id":567,"date":"2014-05-19T11:37:51","date_gmt":"2014-05-19T03:37:51","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=567"},"modified":"2016-07-15T17:28:51","modified_gmt":"2016-07-15T09:28:51","slug":"%e9%80%9a%e7%9f%a5%e6%9c%ba%e5%88%b6%ef%bc%88%e5%88%9d%e5%ad%a6%e8%80%85%e5%bf%85%e9%a1%bb%e7%9f%a5%e9%81%93%e7%9a%84%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/05\/19\/113751567.html","title":{"rendered":"\u901a\u77e5\u673a\u5236\uff08\u521d\u5b66\u8005\u5fc5\u987b\u77e5\u9053\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff09"},"content":{"rendered":"<p>\u901a\u77e5\u662f\u4e00\u79cd\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u4e0e\u4ee3\u7406\u6709\u7c7b\u4f3c\u7684\u5730\u65b9\uff0c\u4e00\u822c\u5b9e\u73b0\u5206\u4e3a\u51e0\u4e2a\u6b65\u9aa4<\/p>\n<p><strong>1\u3001\u8bbe\u7f6e\u76d1\u542c<\/strong><\/p>\n<p>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(<strong>recive<\/strong>: ) name:@&#8221;<strong>notification<\/strong>&#8221; object:nil];<\/p>\n<p><strong>2\u3001\u53d1\u9001\u901a\u77e5<\/strong><\/p>\n<p>NSDictionary *dic = [NSDictionary dictionaryWithObject:@&#8221;value&#8221; forKey:@&#8221;key&#8221;];<\/p>\n<p>[[NSNotificationCenter defaultCenter] postNotificationName:@&#8221;<strong>notification<\/strong>&#8221; object:nil <strong>userInfo:dic<\/strong>];<\/p>\n<p><strong>3\u3001\u901a\u77e5\u54cd\u5e94<\/strong><\/p>\n<p>&#8211; (void)<strong>recive<\/strong>:(NSDictionary *)<strong>userInfo<\/strong><br \/>\n{<br \/>\nNSLog(@&#8221;%@&#8221;, userInfo);<br \/>\n}<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre lang=\"objc\" line=\"1\">@implementation SAViewController\n\n-(id)init\n{\n    if (self = [super init]){\n        self.view.backgroundColor = [UIColor whiteColor];\n        \n        \/\/ 1\u3001\u8bbe\u7f6e\u76d1\u542c\n        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recive:) name:@\"notification\" object:nil];\n        \n        \/\/ \u521b\u5efa\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u6309\u94ae\u70b9\u51fb\u65f6\u89e6\u53d1\u901a\u77e5\u53d1\u9001\u4e8b\u4ef6\n        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];\n        button.frame = CGRectMake(10, 50, 50, 30);\n        [button setTitle:@\"abc\" forState:UIControlStateNormal];\n        [self.view addSubview:button];\n        [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];\n    }\n    return self;\n}\n\n- (void)buttonClick\n{\n    \n    \/\/ 2\u3001\u53d1\u9001\u901a\u77e5\n    NSDictionary *dic = [NSDictionary dictionaryWithObject:@\"value\" forKey:@\"key\"];\n    \n    [[NSNotificationCenter defaultCenter] postNotificationName:@\"notification\" object:nil userInfo:dic];\n\n}\n\n\/\/ 3\u3001\u901a\u77e5\u54cd\u5e94\n- (void)recive:(NSDictionary *)userInfo\n{\n    NSLog(@\"%@\", userInfo);\n}\n@end<\/pre>\n<p>PS:\u8fd9\u79cd\u8bbe\u8ba1\u6a21\u5f0f\u4e00\u822c\u5728\u63a7\u5236\u5668\u4e0e\u63a7\u5236\u5668\u4e4b\u95f4\u6570\u636e\u4ea4\u4e92\u573a\u666f\u4e0b\u4f7f\u7528\uff0c\u901a\u77e5\u7684\u53d1\u9001\u8005\u4e0e\u63a5\u6536\u8005\u4e00\u822c\u90fd\u4e0d\u662f\u540c\u4e00\u4e2a\u63a7\u5236\u5668\uff0c\u5426\u5219\u76f4\u63a5\u8c03\u65b9\u6cd5\u4e0d\u5c31\u884c\u4e86\u5417\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u77e5\u662f\u4e00\u79cd\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u4e0e\u4ee3\u7406\u6709\u7c7b\u4f3c\u7684\u5730\u65b9\uff0c\u4e00\u822c\u5b9e\u73b0\u5206\u4e3a\u51e0\u4e2a\u6b65\u9aa4 1\u3001\u8bbe\u7f6e\u76d1\u542c [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recive: ) name:@&#8221;notification&#8221; object:nil]; 2\u3001\u53d1\u9001\u901a\u77e5 NSDictionary *dic = [NSDictionary dictionaryWithObject:@&#8221;value&#8221; forKey:@&#8221;key&#8221;]; [[NSNotificationCenter defaultCenter] postNotificationName:@&#8221;notification&#8221; object:nil userInfo:dic]; 3\u3001\u901a\u77e5\u54cd\u5e94 &#8211; (void)recive:(NSDictionary *)userInfo { NSLog(@&#8221;%@&#8221;, userInfo); } \u793a\u4f8b\uff1a @implementation SAViewController -(id)init { if (self = [super init]){ self.view.backgroundColor = [UIColor whiteColor]; \/\/ 1\u3001\u8bbe\u7f6e\u76d1\u542c [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recive:) name:@&#8221;notification&#8221; object:nil]; \/\/ \u521b\u5efa\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u6309\u94ae\u70b9\u51fb\u65f6\u89e6\u53d1\u901a\u77e5\u53d1\u9001\u4e8b\u4ef6 UIButton *button [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[20],"class_list":["post-567","post","type-post","status-publish","format-standard","hentry","category-project","tag-basics"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=567"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/567\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}