{"id":353,"date":"2015-12-13T18:58:07","date_gmt":"2015-12-13T10:58:07","guid":{"rendered":"http:\/\/weitaoc.com\/?p=353"},"modified":"2019-09-27T14:18:21","modified_gmt":"2019-09-27T06:18:21","slug":"ios%e4%b8%ad%e5%bb%b6%e6%97%b6%e6%89%a7%e8%a1%8c%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e5%bc%8f%e7%9a%84%e6%af%94%e8%be%83%e5%92%8c%e6%b1%87%e6%80%bb%e8%bd%ac%e8%bd%bd","status":"publish","type":"post","link":"http:\/\/weitaoc.com\/?p=353","title":{"rendered":"IOS\u4e2d\u5ef6\u65f6\u6267\u884c\u7684\u51e0\u79cd\u65b9\u5f0f\u7684\u6bd4\u8f83\u548c\u6c47\u603b(\u8f6c\u8f7d)"},"content":{"rendered":"<p>\u672c\u6587\u5217\u4e3e\u4e86\u56db\u79cd\u5ef6\u65f6\u6267\u884c\u67d0\u51fd\u6570\u7684\u65b9\u6cd5\u53ca\u5176\u4e00\u4e9b\u533a\u522b\u3002\u5047\u5982\u5ef6\u65f61\u79d2\u65f6\u95f4\u6267\u884c\u4e0b\u9762\u7684\u65b9\u6cd5\u3002<\/p>\n<div class=\"codecolorer-container text geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\" style=\"white-space:nowrap\">- (void)delayMethod { NSLog(@&quot;execute&quot;); }<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p><span style=\"font-family: 'arial black', sans-serif; font-size: 14pt;\">1.performSelector\u65b9\u6cd5<\/span><\/p>\n<div class=\"codecolorer-container text geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\" style=\"white-space:nowrap\">[self performSelector:@selector(delayMethod) withObject:nil afterDelay:1.0f];<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u6b64\u65b9\u5f0f\u8981\u6c42\u5fc5\u987b\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u6267\u884c\uff0c\u5426\u5219\u65e0\u6548\u3002<br \/>\n\u662f\u4e00\u79cd\u975e\u963b\u585e\u7684\u6267\u884c\u65b9\u5f0f\uff0c<br \/>\n\u6682\u65f6\u672a\u627e\u5230\u53d6\u6d88\u6267\u884c\u7684\u65b9\u6cd5\u3002<\/p>\n<p><span style=\"font-family: 'arial black', sans-serif; font-size: 14pt;\">2.\u5b9a\u65f6\u5668:NSTimer<\/span><\/p>\n<div class=\"codecolorer-container text geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/><\/div><\/td><td><div class=\"text codecolorer\" style=\"white-space:nowrap\">[NSTimer scheduledTimerWithTimeInterval:1.0f target:self<br \/>\n<br \/>\nselector:@selector(delayMethod) userInfo:nil repeats:NO];<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u6b64\u65b9\u5f0f\u8981\u6c42\u5fc5\u987b\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u6267\u884c\uff0c\u5426\u5219\u65e0\u6548\u3002<br \/>\n\u662f\u4e00\u79cd\u975e\u963b\u585e\u7684\u6267\u884c\u65b9\u5f0f\uff0c<br \/>\n\u53ef\u4ee5\u901a\u8fc7NSTimer\u7c7b\u7684- (void)invalidate;\u53d6\u6d88\u6267\u884c\u3002<\/p>\n<p><span style=\"font-family: 'arial black', sans-serif; font-size: 14pt;\">3. sleep\u65b9\u5f0f<\/span><\/p>\n<div class=\"codecolorer-container text geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\" style=\"white-space:nowrap\">[NSThread sleepForTimeInterval:1.0f]; [self delayMethod];<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u6b64\u65b9\u5f0f\u5728\u4e3b\u7ebf\u7a0b\u548c\u5b50\u7ebf\u7a0b\u4e2d\u5747\u53ef\u6267\u884c\u3002<br \/>\n\u662f\u4e00\u79cd\u963b\u585e\u7684\u6267\u884c\u65b9\u5f0f\uff0c\u5efa\u65b9\u653e\u5230\u5b50\u7ebf\u7a0b\u4e2d\uff0c\u4ee5\u514d\u5361\u4f4f\u754c\u9762<br \/>\n\u6ca1\u6709\u627e\u5230\u53d6\u6d88\u6267\u884c\u7684\u65b9\u6cd5\u3002<\/p>\n<p><span style=\"font-family: 'arial black', sans-serif; font-size: 14pt;\">4.GCD\u65b9\u5f0f<\/span><\/p>\n<div class=\"codecolorer-container text geshi\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/><\/div><\/td><td><div class=\"text codecolorer\" style=\"white-space:nowrap\">double delayInSeconds = 1.0;<br \/>\n__block ViewController* bself = self;<br \/>\ndispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));<br \/>\ndispatch_after(popTime, dispatch_get_main_queue(), ^(void){[bself delayMethod]; });<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>\u6b64\u65b9\u5f0f\u5728\u53ef\u4ee5\u5728\u53c2\u6570\u4e2d\u9009\u62e9\u6267\u884c\u7684\u7ebf\u7a0b\u3002<br \/>\n\u662f\u4e00\u79cd\u975e\u963b\u585e\u7684\u6267\u884c\u65b9\u5f0f\uff0c<br \/>\n\u6ca1\u6709\u627e\u5230\u53d6\u6d88\u6267\u884c\u7684\u65b9\u6cd5\u3002<\/p>\n<p><a href=\"http:\/\/weitaoc.com\/archives\/353\/attachment\/2011310173438\" rel=\"attachment wp-att-354\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-354\" src=\"http:\/\/weitaoc.com\/wp-content\/uploads\/2015\/12\/2011310173438.jpg\" alt=\"2011310173438\" width=\"175\" height=\"172\" \/><\/a><\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"http:\/\/weitaoc.com\">\u8ff7\u8def\u7684\u8001\u9f20<\/a> &raquo; <a href=\"http:\/\/weitaoc.com\/?p=353\">IOS\u4e2d\u5ef6\u65f6\u6267\u884c\u7684\u51e0\u79cd\u65b9\u5f0f\u7684\u6bd4\u8f83\u548c\u6c47\u603b(\u8f6c\u8f7d)<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5217\u4e3e\u4e86\u56db\u79cd\u5ef6\u65f6\u6267\u884c\u67d0\u51fd\u6570\u7684\u65b9\u6cd5\u53ca\u5176\u4e00\u4e9b\u533a\u522b\u3002\u5047\u5982\u5ef6\u65f61\u79d2\u65f6\u95f4\u6267\u884c\u4e0b\u9762\u7684\u65b9\u6cd5\u3002 1- (void)delayMethod { NSLog(@&quot;execute&quot;); } 1.performSelector\u65b9\u6cd5 1[self per [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58,4],"tags":[53],"class_list":["post-353","post","type-post","status-publish","format-standard","hentry","category-other","category-technology","tag-ios"],"views":7126,"_links":{"self":[{"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/posts\/353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=353"}],"version-history":[{"count":3,"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/posts\/353\/revisions"}],"predecessor-version":[{"id":357,"href":"http:\/\/weitaoc.com\/index.php?rest_route=\/wp\/v2\/posts\/353\/revisions\/357"}],"wp:attachment":[{"href":"http:\/\/weitaoc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=353"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weitaoc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}