{"id":3854,"date":"2016-04-25T14:27:35","date_gmt":"2016-04-25T06:27:35","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=3854"},"modified":"2016-04-25T14:27:35","modified_gmt":"2016-04-25T06:27:35","slug":"%e6%9d%82%e8%b0%88-ios-%e5%bc%80%e5%8f%91%e8%b7%b3%e5%9d%91%e8%ae%b0%ef%bc%9a%e4%bd%bf%e7%94%a8-nsset-%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=3854","title":{"rendered":"[\u6742\u8c08] iOS \u5f00\u53d1\u8df3\u5751\u8bb0\uff1a\u4f7f\u7528 NSSet \u5bf9\u8c61"},"content":{"rendered":"<p>Delphi \u4e2d\u5f00\u53d1 iOS \u7a0b\u5e8f\u4e2d\uff0c\u8bb8\u591a\u5730\u65b9\u9700\u8981\u4e00\u4e2a NSSet \u7c7b\u578b\u7684\u53c2\u6570\uff0c\u4f46\u662f\uff0c\u600e\u4e48\u4f7f\u7528\u5f88\u4f24\u8111\u7b4b\u3002\u53ef\u601c\u7684\u5c11\u7684\u53ef\u601c\u7684\u6587\u6863\uff0c\u90fd\u4e0d\u5982\u6211\u7684 QDAC \u4e86\uff08\u81f3\u5c11\u4ffa\u7edd\u5927\u90e8\u5206\u4ee3\u7801\u6709\u51fd\u6570\u6ce8\u91ca\uff0c\u8fd9\u8fde\u4e2a\u6ce8\u91ca\u90fd\u6ca1\u6709\uff09\u3002\u4e3a\u4e86\u641e\u660e\u767d\u600e\u4e48\u7528\uff0c\u672c\u4eba\u5229\u7528\u4e86\u6e90\u7801\u641c\u7d22\u5927\u6cd5\uff0c\u641c\u7d22 Delphi \u81ea\u5e26\u7684 Source \u76ee\u5f55\u4e0b\uff0c\u770b\u770b\u5b83\u81ea\u8eab\u662f\u5982\u4f55\u4f7f\u7528\u7684\u3002\u6574\u4e2a\u6e90\u7801\u4e2d\u627e\u5230\u56db\u5904\u4f4d\u7f6e\uff1a<\/p>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/NSSetFiles.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3855\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/NSSetFiles.jpg\" alt=\"NSSetFiles\" width=\"787\" height=\"194\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/NSSetFiles.jpg 787w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/NSSetFiles-300x74.jpg 300w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/NSSetFiles-768x189.jpg 768w\" sizes=\"auto, (max-width: 787px) 100vw, 787px\" \/><\/a><\/p>\n<p>\u597d\u4e86\uff0c\u63a5\u4e0b\u6765\u5206\u6790\u4e0b\uff0c\u540e\u9762\u4e24\u4e2a\u660e\u663e\u662f\u58f0\u660e\uff0c\u4ffa\u4eec\u5c31\u4e0d\u5173\u5fc3\u4e86\u3002\u524d\u9762\u4e24\u4e2a\u624d\u662f\u5b9e\u9645\u4f7f\u7528\u7684\u4f8b\u5b50\uff0c\u53ef\u4ee5\u770b\u5230\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ol>\n<li>NSSet \u5bf9\u8c61\u4e0d\u662f\u901a\u8fc7 TNSSet.Create \u65b9\u6cd5\uff0c\u8bf4\u660e\u8fd9\u4e48\u505a\u662f\u4e0d\u5bf9\u7684\uff08\u5426\u5219\u5b98\u65b9\u4e3a\u5565\u4e0d\u8fd9\u4e48\u5e72\uff0c\u5bf9\u4e0d\uff1f\uff09\uff0c\u81f3\u4e8e\u4e3a\u4ec0\u4e48\uff0c\u6211\u4e0d\u77e5\u9053\uff0c\u6ca1\u7ec6\u7814\u7a76\uff0c\u522b\u95ee\u6211:)<\/li>\n<li>NSSet \u662f\u901a\u8fc7 TNSSet.OCClass.setXXX \u65b9\u6cd5\u521b\u5efa\u5b9e\u4f8b\uff0c\u7136\u540e\u901a\u8fc7 TNSSet.Wrap \u8f6c\u6362\u4e3a NSSet \u63a5\u53e3\u7684\u3002<\/li>\n<\/ol>\n<p>\u73b0\u5728\u6765\u770b\u4e0b\u6e90\u7801\u4e2d\u7684\u7528\u6cd5\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">procedure TiOSBannerAd.SetBannerAdControl(const AValue: TCustomBannerAd);\r\nvar\r\n  SizesArray: NSMutableArray;\r\n  SizesSet: NSSet;\r\nbegin\r\n  FAdControl := AValue;\r\n  if FAdControl &lt;&gt; nil then\r\n  begin\r\n    FAd := TADBannerView.Create;\r\n    FDelegate := TiOSBannerAdDelegate.Create;\r\n    FDelegate.SetAd(Self);\r\n    FAd.setDelegate(FDelegate.GetObjectID);\r\n    SizesArray := TNSMutableArray.Create;\r\n    SizesArray.addObject((ADBannerContentSizeIdentifierLandscape as ILocalObject).GetObjectID);\r\n    SizesArray.addObject((ADBannerContentSizeIdentifierPortrait as ILocalObject).GetObjectID);\r\n    SizesSet := TNSSet.Wrap(TNSSet.OCClass.setWithArray(SizesArray));\r\n    SizesArray.release;\r\n    FAd.setRequiredContentSizeIdentifiers(SizesSet);\r\n\r\n    UpdateControlMetrics\r\n  end\r\n  else\r\n  begin\r\n    FAd.setDelegate(nil);\r\n    FAd.release;\r\n    FAd := nil;\r\n    FDelegate := nil;\r\n  end;\r\nend;<\/pre>\n<p>\u597d\u5427\uff0cTNSMutableArray \u662f\u53ef\u4ee5\u521b\u5efa\u5b9e\u4f8b\u7684\uff0c\u6ce8\u610f addObject \u6dfb\u52a0\u7684\u5bf9\u8c61\u9700\u8981\u5148\u5c06\u63a5\u53e3\u8f6c\u6362\u4e3a ILocalObject \uff0c\u7136\u540e\u8c03\u7528 GetObjectID\uff0c\u8fd4\u56de\u7684\u6307\u9488\u624d\u662f\u9700\u8981\u7684\u5bf9\u8c61\u5730\u5740\u3002\u611f\u89c9\u597d\u9ebb\u70e6\u5bf9\u4e0d\u5bf9\uff0c\u597d\u5427\uff0c\u9ebb\u70e6\u4e5f\u5c31\u9ebb\u70e6\u4e86\uff0c\u4e0d\u8fc7\u6211\u662f\u4e00\u4e2a\u6015\u9ebb\u70e6\u7684\u4eba\uff0c\u8bb0\u4f4f\u8fd9\u4e48\u4e00\u5806\u4e1c\u897f\u8111\u4ec1\u4f1a\u6bd4\u8f83\u75db\u82e6\uff08\u5929\u751f\u8111\u5bb9\u91cf\u5c0f\uff0c\u8bb0\u4e0d\u4f4f\u4e8b\uff09\uff0c\u6240\u4ee5\u5c01\u88c5\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u5206\u4eab\u7ed9\u5927\u5bb6\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">function NSObjectArray(const AItems: array of IInterface): NSArray;\r\nvar\r\n  I: Integer;\r\n  ATemp: NSMutableArray;\r\nbegin\r\n  ATemp := TNSMutableArray.Create;\r\n  Result := ATemp;\r\n  for I := 0 to High(AItems) do\r\n    ATemp.addObject((AItems[I] as ILocalObject).GetObjectID);\r\nend;\r\n\r\nfunction NSArraySet(const AItems: array of IInterface): NSSet;\r\nvar\r\n  I: Integer;\r\nbegin\r\n  Result := TNSSet.Wrap(TNSSet.OCClass.setWithArray(NSObjectArray(AItems)));\r\nend;<\/pre>\n<p>\u8fd9\u6837\u8c61\u4e0a\u9762\u5b98\u65b9\u7684\u4ee3\u7801\u4e2d\u76f8\u5173\u7684\u90e8\u5206\u5c31\u53ef\u4ee5\u76f4\u63a5\u5199\u6210\uff1a<\/p>\n<pre class=\"lang:delphi decode:true\">SizesSet := NSArraySet([ADBannerContentSizeIdentifierLandscape,ADBannerContentSizeIdentifierPortrait]);<\/pre>\n<p>\u662f\u4e0d\u662f\u611f\u89c9\u53ef\u8bfb\u6027\u597d\u591a\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Delphi \u4e2d\u5f00\u53d1 iOS \u7a0b\u5e8f\u4e2d\uff0c\u8bb8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8,602,21],"tags":[612,611],"class_list":["post-3854","post","type-post","status-publish","format-standard","hentry","category-delphi","category-ios","category-misc","tag-nsarray","tag-nsset"],"views":3083,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3854"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3854\/revisions"}],"predecessor-version":[{"id":3856,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3854\/revisions\/3856"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}