├── README.md ├── 多代理.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── sakai.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── sakai.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── xcschememanagement.plist │ └── 多代理.xcscheme ├── 多代理 ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── CustomTableViewCell.h ├── CustomTableViewCell.m ├── DelegateShare.h ├── DelegateShare.m ├── Info.plist ├── SecondViewController.h ├── SecondViewController.m ├── ViewController.h ├── ViewController.m └── main.m ├── 多代理Tests ├── Info.plist └── ___Tests.m └── 多代理UITests ├── Info.plist └── ___UITests.m /README.md: -------------------------------------------------------------------------------- 1 | # iOS-More-delegate 2 | iOS 多代理实现,以及多block传值 3 | 面向对象的 多代理, 以及多block 传值.用于定向 传值,在不使用的时候可以移除. 用于取代消息通知,适用于很多情况,具体因人而异. 4 | 算是一个开发优化的小技巧.欢迎大家有更好的实现方式. 5 | 如果你觉得可以,麻烦给我个 star ! 6 | 7 | 详细介绍点击简书 8 | 简书地址: 9 | http://www.jianshu.com/p/ea5ef09993e8 10 | -------------------------------------------------------------------------------- /多代理.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BAC2EDC51CB3BF3100606DA2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC2EDC41CB3BF3100606DA2 /* main.m */; }; 11 | BAC2EDC81CB3BF3100606DA2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC2EDC71CB3BF3100606DA2 /* AppDelegate.m */; }; 12 | BAC2EDCB1CB3BF3100606DA2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC2EDCA1CB3BF3100606DA2 /* ViewController.m */; }; 13 | BAC2EDCE1CB3BF3100606DA2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BAC2EDCC1CB3BF3100606DA2 /* Main.storyboard */; }; 14 | BAC2EDD01CB3BF3100606DA2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BAC2EDCF1CB3BF3100606DA2 /* Assets.xcassets */; }; 15 | BAC2EDD31CB3BF3100606DA2 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BAC2EDD11CB3BF3100606DA2 /* LaunchScreen.storyboard */; }; 16 | BAC2EDDE1CB3BF3100606DA2 /* ___Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC2EDDD1CB3BF3100606DA2 /* ___Tests.m */; }; 17 | BAC2EDE91CB3BF3100606DA2 /* ___UITests.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC2EDE81CB3BF3100606DA2 /* ___UITests.m */; }; 18 | BAC2EDF81CB3C11E00606DA2 /* CustomTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC2EDF71CB3C11E00606DA2 /* CustomTableViewCell.m */; }; 19 | BAC2EDFB1CB3C1A500606DA2 /* DelegateShare.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC2EDFA1CB3C1A500606DA2 /* DelegateShare.m */; }; 20 | BAC2EDFE1CB4F91900606DA2 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BAC2EDFD1CB4F91900606DA2 /* SecondViewController.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | BAC2EDDA1CB3BF3100606DA2 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = BAC2EDB81CB3BF3100606DA2 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = BAC2EDBF1CB3BF3100606DA2; 29 | remoteInfo = "多代理"; 30 | }; 31 | BAC2EDE51CB3BF3100606DA2 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = BAC2EDB81CB3BF3100606DA2 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = BAC2EDBF1CB3BF3100606DA2; 36 | remoteInfo = "多代理"; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | BAC2EDC01CB3BF3100606DA2 /* 多代理.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "多代理.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | BAC2EDC41CB3BF3100606DA2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 43 | BAC2EDC61CB3BF3100606DA2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 44 | BAC2EDC71CB3BF3100606DA2 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 45 | BAC2EDC91CB3BF3100606DA2 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 46 | BAC2EDCA1CB3BF3100606DA2 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 47 | BAC2EDCD1CB3BF3100606DA2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 48 | BAC2EDCF1CB3BF3100606DA2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | BAC2EDD21CB3BF3100606DA2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 50 | BAC2EDD41CB3BF3100606DA2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | BAC2EDD91CB3BF3100606DA2 /* 多代理Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "多代理Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | BAC2EDDD1CB3BF3100606DA2 /* ___Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "___Tests.m"; sourceTree = ""; }; 53 | BAC2EDDF1CB3BF3100606DA2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | BAC2EDE41CB3BF3100606DA2 /* 多代理UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "多代理UITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | BAC2EDE81CB3BF3100606DA2 /* ___UITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "___UITests.m"; sourceTree = ""; }; 56 | BAC2EDEA1CB3BF3100606DA2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | BAC2EDF61CB3C11E00606DA2 /* CustomTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomTableViewCell.h; sourceTree = ""; }; 58 | BAC2EDF71CB3C11E00606DA2 /* CustomTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomTableViewCell.m; sourceTree = ""; }; 59 | BAC2EDF91CB3C1A500606DA2 /* DelegateShare.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DelegateShare.h; path = "多代理/DelegateShare.h"; sourceTree = ""; }; 60 | BAC2EDFA1CB3C1A500606DA2 /* DelegateShare.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DelegateShare.m; path = "多代理/DelegateShare.m"; sourceTree = ""; }; 61 | BAC2EDFC1CB4F91900606DA2 /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; 62 | BAC2EDFD1CB4F91900606DA2 /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; 63 | /* End PBXFileReference section */ 64 | 65 | /* Begin PBXFrameworksBuildPhase section */ 66 | BAC2EDBD1CB3BF3100606DA2 /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | ); 71 | runOnlyForDeploymentPostprocessing = 0; 72 | }; 73 | BAC2EDD61CB3BF3100606DA2 /* Frameworks */ = { 74 | isa = PBXFrameworksBuildPhase; 75 | buildActionMask = 2147483647; 76 | files = ( 77 | ); 78 | runOnlyForDeploymentPostprocessing = 0; 79 | }; 80 | BAC2EDE11CB3BF3100606DA2 /* Frameworks */ = { 81 | isa = PBXFrameworksBuildPhase; 82 | buildActionMask = 2147483647; 83 | files = ( 84 | ); 85 | runOnlyForDeploymentPostprocessing = 0; 86 | }; 87 | /* End PBXFrameworksBuildPhase section */ 88 | 89 | /* Begin PBXGroup section */ 90 | BAC2EDB71CB3BF3100606DA2 = { 91 | isa = PBXGroup; 92 | children = ( 93 | BAC2EDF91CB3C1A500606DA2 /* DelegateShare.h */, 94 | BAC2EDFA1CB3C1A500606DA2 /* DelegateShare.m */, 95 | BAC2EDC21CB3BF3100606DA2 /* 多代理 */, 96 | BAC2EDDC1CB3BF3100606DA2 /* 多代理Tests */, 97 | BAC2EDE71CB3BF3100606DA2 /* 多代理UITests */, 98 | BAC2EDC11CB3BF3100606DA2 /* Products */, 99 | ); 100 | sourceTree = ""; 101 | }; 102 | BAC2EDC11CB3BF3100606DA2 /* Products */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | BAC2EDC01CB3BF3100606DA2 /* 多代理.app */, 106 | BAC2EDD91CB3BF3100606DA2 /* 多代理Tests.xctest */, 107 | BAC2EDE41CB3BF3100606DA2 /* 多代理UITests.xctest */, 108 | ); 109 | name = Products; 110 | sourceTree = ""; 111 | }; 112 | BAC2EDC21CB3BF3100606DA2 /* 多代理 */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | BAC2EDC61CB3BF3100606DA2 /* AppDelegate.h */, 116 | BAC2EDC71CB3BF3100606DA2 /* AppDelegate.m */, 117 | BAC2EDC91CB3BF3100606DA2 /* ViewController.h */, 118 | BAC2EDCA1CB3BF3100606DA2 /* ViewController.m */, 119 | BAC2EDFC1CB4F91900606DA2 /* SecondViewController.h */, 120 | BAC2EDFD1CB4F91900606DA2 /* SecondViewController.m */, 121 | BAC2EDF61CB3C11E00606DA2 /* CustomTableViewCell.h */, 122 | BAC2EDF71CB3C11E00606DA2 /* CustomTableViewCell.m */, 123 | BAC2EDCC1CB3BF3100606DA2 /* Main.storyboard */, 124 | BAC2EDCF1CB3BF3100606DA2 /* Assets.xcassets */, 125 | BAC2EDD11CB3BF3100606DA2 /* LaunchScreen.storyboard */, 126 | BAC2EDD41CB3BF3100606DA2 /* Info.plist */, 127 | BAC2EDC31CB3BF3100606DA2 /* Supporting Files */, 128 | ); 129 | path = "多代理"; 130 | sourceTree = ""; 131 | }; 132 | BAC2EDC31CB3BF3100606DA2 /* Supporting Files */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | BAC2EDC41CB3BF3100606DA2 /* main.m */, 136 | ); 137 | name = "Supporting Files"; 138 | sourceTree = ""; 139 | }; 140 | BAC2EDDC1CB3BF3100606DA2 /* 多代理Tests */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | BAC2EDDD1CB3BF3100606DA2 /* ___Tests.m */, 144 | BAC2EDDF1CB3BF3100606DA2 /* Info.plist */, 145 | ); 146 | path = "多代理Tests"; 147 | sourceTree = ""; 148 | }; 149 | BAC2EDE71CB3BF3100606DA2 /* 多代理UITests */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | BAC2EDE81CB3BF3100606DA2 /* ___UITests.m */, 153 | BAC2EDEA1CB3BF3100606DA2 /* Info.plist */, 154 | ); 155 | path = "多代理UITests"; 156 | sourceTree = ""; 157 | }; 158 | /* End PBXGroup section */ 159 | 160 | /* Begin PBXNativeTarget section */ 161 | BAC2EDBF1CB3BF3100606DA2 /* 多代理 */ = { 162 | isa = PBXNativeTarget; 163 | buildConfigurationList = BAC2EDED1CB3BF3100606DA2 /* Build configuration list for PBXNativeTarget "多代理" */; 164 | buildPhases = ( 165 | BAC2EDBC1CB3BF3100606DA2 /* Sources */, 166 | BAC2EDBD1CB3BF3100606DA2 /* Frameworks */, 167 | BAC2EDBE1CB3BF3100606DA2 /* Resources */, 168 | ); 169 | buildRules = ( 170 | ); 171 | dependencies = ( 172 | ); 173 | name = "多代理"; 174 | productName = "多代理"; 175 | productReference = BAC2EDC01CB3BF3100606DA2 /* 多代理.app */; 176 | productType = "com.apple.product-type.application"; 177 | }; 178 | BAC2EDD81CB3BF3100606DA2 /* 多代理Tests */ = { 179 | isa = PBXNativeTarget; 180 | buildConfigurationList = BAC2EDF01CB3BF3100606DA2 /* Build configuration list for PBXNativeTarget "多代理Tests" */; 181 | buildPhases = ( 182 | BAC2EDD51CB3BF3100606DA2 /* Sources */, 183 | BAC2EDD61CB3BF3100606DA2 /* Frameworks */, 184 | BAC2EDD71CB3BF3100606DA2 /* Resources */, 185 | ); 186 | buildRules = ( 187 | ); 188 | dependencies = ( 189 | BAC2EDDB1CB3BF3100606DA2 /* PBXTargetDependency */, 190 | ); 191 | name = "多代理Tests"; 192 | productName = "多代理Tests"; 193 | productReference = BAC2EDD91CB3BF3100606DA2 /* 多代理Tests.xctest */; 194 | productType = "com.apple.product-type.bundle.unit-test"; 195 | }; 196 | BAC2EDE31CB3BF3100606DA2 /* 多代理UITests */ = { 197 | isa = PBXNativeTarget; 198 | buildConfigurationList = BAC2EDF31CB3BF3100606DA2 /* Build configuration list for PBXNativeTarget "多代理UITests" */; 199 | buildPhases = ( 200 | BAC2EDE01CB3BF3100606DA2 /* Sources */, 201 | BAC2EDE11CB3BF3100606DA2 /* Frameworks */, 202 | BAC2EDE21CB3BF3100606DA2 /* Resources */, 203 | ); 204 | buildRules = ( 205 | ); 206 | dependencies = ( 207 | BAC2EDE61CB3BF3100606DA2 /* PBXTargetDependency */, 208 | ); 209 | name = "多代理UITests"; 210 | productName = "多代理UITests"; 211 | productReference = BAC2EDE41CB3BF3100606DA2 /* 多代理UITests.xctest */; 212 | productType = "com.apple.product-type.bundle.ui-testing"; 213 | }; 214 | /* End PBXNativeTarget section */ 215 | 216 | /* Begin PBXProject section */ 217 | BAC2EDB81CB3BF3100606DA2 /* Project object */ = { 218 | isa = PBXProject; 219 | attributes = { 220 | LastUpgradeCheck = 0720; 221 | ORGANIZATIONNAME = "邴天宇"; 222 | TargetAttributes = { 223 | BAC2EDBF1CB3BF3100606DA2 = { 224 | CreatedOnToolsVersion = 7.2; 225 | }; 226 | BAC2EDD81CB3BF3100606DA2 = { 227 | CreatedOnToolsVersion = 7.2; 228 | TestTargetID = BAC2EDBF1CB3BF3100606DA2; 229 | }; 230 | BAC2EDE31CB3BF3100606DA2 = { 231 | CreatedOnToolsVersion = 7.2; 232 | TestTargetID = BAC2EDBF1CB3BF3100606DA2; 233 | }; 234 | }; 235 | }; 236 | buildConfigurationList = BAC2EDBB1CB3BF3100606DA2 /* Build configuration list for PBXProject "多代理" */; 237 | compatibilityVersion = "Xcode 3.2"; 238 | developmentRegion = English; 239 | hasScannedForEncodings = 0; 240 | knownRegions = ( 241 | en, 242 | Base, 243 | ); 244 | mainGroup = BAC2EDB71CB3BF3100606DA2; 245 | productRefGroup = BAC2EDC11CB3BF3100606DA2 /* Products */; 246 | projectDirPath = ""; 247 | projectRoot = ""; 248 | targets = ( 249 | BAC2EDBF1CB3BF3100606DA2 /* 多代理 */, 250 | BAC2EDD81CB3BF3100606DA2 /* 多代理Tests */, 251 | BAC2EDE31CB3BF3100606DA2 /* 多代理UITests */, 252 | ); 253 | }; 254 | /* End PBXProject section */ 255 | 256 | /* Begin PBXResourcesBuildPhase section */ 257 | BAC2EDBE1CB3BF3100606DA2 /* Resources */ = { 258 | isa = PBXResourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | BAC2EDD31CB3BF3100606DA2 /* LaunchScreen.storyboard in Resources */, 262 | BAC2EDD01CB3BF3100606DA2 /* Assets.xcassets in Resources */, 263 | BAC2EDCE1CB3BF3100606DA2 /* Main.storyboard in Resources */, 264 | ); 265 | runOnlyForDeploymentPostprocessing = 0; 266 | }; 267 | BAC2EDD71CB3BF3100606DA2 /* Resources */ = { 268 | isa = PBXResourcesBuildPhase; 269 | buildActionMask = 2147483647; 270 | files = ( 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | }; 274 | BAC2EDE21CB3BF3100606DA2 /* Resources */ = { 275 | isa = PBXResourcesBuildPhase; 276 | buildActionMask = 2147483647; 277 | files = ( 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | /* End PBXResourcesBuildPhase section */ 282 | 283 | /* Begin PBXSourcesBuildPhase section */ 284 | BAC2EDBC1CB3BF3100606DA2 /* Sources */ = { 285 | isa = PBXSourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | BAC2EDFE1CB4F91900606DA2 /* SecondViewController.m in Sources */, 289 | BAC2EDCB1CB3BF3100606DA2 /* ViewController.m in Sources */, 290 | BAC2EDC81CB3BF3100606DA2 /* AppDelegate.m in Sources */, 291 | BAC2EDFB1CB3C1A500606DA2 /* DelegateShare.m in Sources */, 292 | BAC2EDF81CB3C11E00606DA2 /* CustomTableViewCell.m in Sources */, 293 | BAC2EDC51CB3BF3100606DA2 /* main.m in Sources */, 294 | ); 295 | runOnlyForDeploymentPostprocessing = 0; 296 | }; 297 | BAC2EDD51CB3BF3100606DA2 /* Sources */ = { 298 | isa = PBXSourcesBuildPhase; 299 | buildActionMask = 2147483647; 300 | files = ( 301 | BAC2EDDE1CB3BF3100606DA2 /* ___Tests.m in Sources */, 302 | ); 303 | runOnlyForDeploymentPostprocessing = 0; 304 | }; 305 | BAC2EDE01CB3BF3100606DA2 /* Sources */ = { 306 | isa = PBXSourcesBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | BAC2EDE91CB3BF3100606DA2 /* ___UITests.m in Sources */, 310 | ); 311 | runOnlyForDeploymentPostprocessing = 0; 312 | }; 313 | /* End PBXSourcesBuildPhase section */ 314 | 315 | /* Begin PBXTargetDependency section */ 316 | BAC2EDDB1CB3BF3100606DA2 /* PBXTargetDependency */ = { 317 | isa = PBXTargetDependency; 318 | target = BAC2EDBF1CB3BF3100606DA2 /* 多代理 */; 319 | targetProxy = BAC2EDDA1CB3BF3100606DA2 /* PBXContainerItemProxy */; 320 | }; 321 | BAC2EDE61CB3BF3100606DA2 /* PBXTargetDependency */ = { 322 | isa = PBXTargetDependency; 323 | target = BAC2EDBF1CB3BF3100606DA2 /* 多代理 */; 324 | targetProxy = BAC2EDE51CB3BF3100606DA2 /* PBXContainerItemProxy */; 325 | }; 326 | /* End PBXTargetDependency section */ 327 | 328 | /* Begin PBXVariantGroup section */ 329 | BAC2EDCC1CB3BF3100606DA2 /* Main.storyboard */ = { 330 | isa = PBXVariantGroup; 331 | children = ( 332 | BAC2EDCD1CB3BF3100606DA2 /* Base */, 333 | ); 334 | name = Main.storyboard; 335 | sourceTree = ""; 336 | }; 337 | BAC2EDD11CB3BF3100606DA2 /* LaunchScreen.storyboard */ = { 338 | isa = PBXVariantGroup; 339 | children = ( 340 | BAC2EDD21CB3BF3100606DA2 /* Base */, 341 | ); 342 | name = LaunchScreen.storyboard; 343 | sourceTree = ""; 344 | }; 345 | /* End PBXVariantGroup section */ 346 | 347 | /* Begin XCBuildConfiguration section */ 348 | BAC2EDEB1CB3BF3100606DA2 /* Debug */ = { 349 | isa = XCBuildConfiguration; 350 | buildSettings = { 351 | ALWAYS_SEARCH_USER_PATHS = NO; 352 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 353 | CLANG_CXX_LIBRARY = "libc++"; 354 | CLANG_ENABLE_MODULES = YES; 355 | CLANG_ENABLE_OBJC_ARC = YES; 356 | CLANG_WARN_BOOL_CONVERSION = YES; 357 | CLANG_WARN_CONSTANT_CONVERSION = YES; 358 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 359 | CLANG_WARN_EMPTY_BODY = YES; 360 | CLANG_WARN_ENUM_CONVERSION = YES; 361 | CLANG_WARN_INT_CONVERSION = YES; 362 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 363 | CLANG_WARN_UNREACHABLE_CODE = YES; 364 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 365 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 366 | COPY_PHASE_STRIP = NO; 367 | DEBUG_INFORMATION_FORMAT = dwarf; 368 | ENABLE_STRICT_OBJC_MSGSEND = YES; 369 | ENABLE_TESTABILITY = YES; 370 | GCC_C_LANGUAGE_STANDARD = gnu99; 371 | GCC_DYNAMIC_NO_PIC = NO; 372 | GCC_NO_COMMON_BLOCKS = YES; 373 | GCC_OPTIMIZATION_LEVEL = 0; 374 | GCC_PREPROCESSOR_DEFINITIONS = ( 375 | "DEBUG=1", 376 | "$(inherited)", 377 | ); 378 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 379 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 380 | GCC_WARN_UNDECLARED_SELECTOR = YES; 381 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 382 | GCC_WARN_UNUSED_FUNCTION = YES; 383 | GCC_WARN_UNUSED_VARIABLE = YES; 384 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 385 | MTL_ENABLE_DEBUG_INFO = YES; 386 | ONLY_ACTIVE_ARCH = YES; 387 | SDKROOT = iphoneos; 388 | TARGETED_DEVICE_FAMILY = "1,2"; 389 | }; 390 | name = Debug; 391 | }; 392 | BAC2EDEC1CB3BF3100606DA2 /* Release */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | ALWAYS_SEARCH_USER_PATHS = NO; 396 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 397 | CLANG_CXX_LIBRARY = "libc++"; 398 | CLANG_ENABLE_MODULES = YES; 399 | CLANG_ENABLE_OBJC_ARC = YES; 400 | CLANG_WARN_BOOL_CONVERSION = YES; 401 | CLANG_WARN_CONSTANT_CONVERSION = YES; 402 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 403 | CLANG_WARN_EMPTY_BODY = YES; 404 | CLANG_WARN_ENUM_CONVERSION = YES; 405 | CLANG_WARN_INT_CONVERSION = YES; 406 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 407 | CLANG_WARN_UNREACHABLE_CODE = YES; 408 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 409 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 410 | COPY_PHASE_STRIP = NO; 411 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 412 | ENABLE_NS_ASSERTIONS = NO; 413 | ENABLE_STRICT_OBJC_MSGSEND = YES; 414 | GCC_C_LANGUAGE_STANDARD = gnu99; 415 | GCC_NO_COMMON_BLOCKS = YES; 416 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 417 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 418 | GCC_WARN_UNDECLARED_SELECTOR = YES; 419 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 420 | GCC_WARN_UNUSED_FUNCTION = YES; 421 | GCC_WARN_UNUSED_VARIABLE = YES; 422 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 423 | MTL_ENABLE_DEBUG_INFO = NO; 424 | SDKROOT = iphoneos; 425 | TARGETED_DEVICE_FAMILY = "1,2"; 426 | VALIDATE_PRODUCT = YES; 427 | }; 428 | name = Release; 429 | }; 430 | BAC2EDEE1CB3BF3100606DA2 /* Debug */ = { 431 | isa = XCBuildConfiguration; 432 | buildSettings = { 433 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 434 | INFOPLIST_FILE = "多代理/Info.plist"; 435 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 436 | PRODUCT_BUNDLE_IDENTIFIER = "qushuawang.---"; 437 | PRODUCT_NAME = "$(TARGET_NAME)"; 438 | }; 439 | name = Debug; 440 | }; 441 | BAC2EDEF1CB3BF3100606DA2 /* Release */ = { 442 | isa = XCBuildConfiguration; 443 | buildSettings = { 444 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 445 | INFOPLIST_FILE = "多代理/Info.plist"; 446 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 447 | PRODUCT_BUNDLE_IDENTIFIER = "qushuawang.---"; 448 | PRODUCT_NAME = "$(TARGET_NAME)"; 449 | }; 450 | name = Release; 451 | }; 452 | BAC2EDF11CB3BF3100606DA2 /* Debug */ = { 453 | isa = XCBuildConfiguration; 454 | buildSettings = { 455 | BUNDLE_LOADER = "$(TEST_HOST)"; 456 | INFOPLIST_FILE = "多代理Tests/Info.plist"; 457 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 458 | PRODUCT_BUNDLE_IDENTIFIER = "qushuawang.---Tests"; 459 | PRODUCT_NAME = "$(TARGET_NAME)"; 460 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/多代理.app/多代理"; 461 | }; 462 | name = Debug; 463 | }; 464 | BAC2EDF21CB3BF3100606DA2 /* Release */ = { 465 | isa = XCBuildConfiguration; 466 | buildSettings = { 467 | BUNDLE_LOADER = "$(TEST_HOST)"; 468 | INFOPLIST_FILE = "多代理Tests/Info.plist"; 469 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 470 | PRODUCT_BUNDLE_IDENTIFIER = "qushuawang.---Tests"; 471 | PRODUCT_NAME = "$(TARGET_NAME)"; 472 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/多代理.app/多代理"; 473 | }; 474 | name = Release; 475 | }; 476 | BAC2EDF41CB3BF3100606DA2 /* Debug */ = { 477 | isa = XCBuildConfiguration; 478 | buildSettings = { 479 | INFOPLIST_FILE = "多代理UITests/Info.plist"; 480 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 481 | PRODUCT_BUNDLE_IDENTIFIER = "qushuawang.---UITests"; 482 | PRODUCT_NAME = "$(TARGET_NAME)"; 483 | TEST_TARGET_NAME = "多代理"; 484 | USES_XCTRUNNER = YES; 485 | }; 486 | name = Debug; 487 | }; 488 | BAC2EDF51CB3BF3100606DA2 /* Release */ = { 489 | isa = XCBuildConfiguration; 490 | buildSettings = { 491 | INFOPLIST_FILE = "多代理UITests/Info.plist"; 492 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 493 | PRODUCT_BUNDLE_IDENTIFIER = "qushuawang.---UITests"; 494 | PRODUCT_NAME = "$(TARGET_NAME)"; 495 | TEST_TARGET_NAME = "多代理"; 496 | USES_XCTRUNNER = YES; 497 | }; 498 | name = Release; 499 | }; 500 | /* End XCBuildConfiguration section */ 501 | 502 | /* Begin XCConfigurationList section */ 503 | BAC2EDBB1CB3BF3100606DA2 /* Build configuration list for PBXProject "多代理" */ = { 504 | isa = XCConfigurationList; 505 | buildConfigurations = ( 506 | BAC2EDEB1CB3BF3100606DA2 /* Debug */, 507 | BAC2EDEC1CB3BF3100606DA2 /* Release */, 508 | ); 509 | defaultConfigurationIsVisible = 0; 510 | defaultConfigurationName = Release; 511 | }; 512 | BAC2EDED1CB3BF3100606DA2 /* Build configuration list for PBXNativeTarget "多代理" */ = { 513 | isa = XCConfigurationList; 514 | buildConfigurations = ( 515 | BAC2EDEE1CB3BF3100606DA2 /* Debug */, 516 | BAC2EDEF1CB3BF3100606DA2 /* Release */, 517 | ); 518 | defaultConfigurationIsVisible = 0; 519 | defaultConfigurationName = Release; 520 | }; 521 | BAC2EDF01CB3BF3100606DA2 /* Build configuration list for PBXNativeTarget "多代理Tests" */ = { 522 | isa = XCConfigurationList; 523 | buildConfigurations = ( 524 | BAC2EDF11CB3BF3100606DA2 /* Debug */, 525 | BAC2EDF21CB3BF3100606DA2 /* Release */, 526 | ); 527 | defaultConfigurationIsVisible = 0; 528 | defaultConfigurationName = Release; 529 | }; 530 | BAC2EDF31CB3BF3100606DA2 /* Build configuration list for PBXNativeTarget "多代理UITests" */ = { 531 | isa = XCConfigurationList; 532 | buildConfigurations = ( 533 | BAC2EDF41CB3BF3100606DA2 /* Debug */, 534 | BAC2EDF51CB3BF3100606DA2 /* Release */, 535 | ); 536 | defaultConfigurationIsVisible = 0; 537 | defaultConfigurationName = Release; 538 | }; 539 | /* End XCConfigurationList section */ 540 | }; 541 | rootObject = BAC2EDB81CB3BF3100606DA2 /* Project object */; 542 | } 543 | -------------------------------------------------------------------------------- /多代理.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /多代理.xcodeproj/project.xcworkspace/xcuserdata/sakai.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangFeng/iOS-More-delegate/1895d3fd7a7b8661133e2e610d7393b249ead90c/多代理.xcodeproj/project.xcworkspace/xcuserdata/sakai.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /多代理.xcodeproj/xcuserdata/sakai.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /多代理.xcodeproj/xcuserdata/sakai.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 多代理.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | BAC2EDBF1CB3BF3100606DA2 16 | 17 | primary 18 | 19 | 20 | BAC2EDD81CB3BF3100606DA2 21 | 22 | primary 23 | 24 | 25 | BAC2EDE31CB3BF3100606DA2 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /多代理.xcodeproj/xcuserdata/sakai.xcuserdatad/xcschemes/多代理.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /多代理/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /多代理/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /多代理/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /多代理/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /多代理/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 55 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 120 | 127 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /多代理/CustomTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomTableViewCell.h 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "DelegateShare.h" 12 | @interface CustomTableViewCell : UITableViewCell 13 | @end 14 | -------------------------------------------------------------------------------- /多代理/CustomTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomTableViewCell.m 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import "CustomTableViewCell.h" 10 | 11 | @implementation CustomTableViewCell 12 | 13 | - (void)awakeFromNib { 14 | // Initialization code 15 | 16 | } 17 | 18 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 19 | { 20 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { 21 | // NSLog(@"%@",self); 22 | [[DelegateShare shareInstance] observer:^(NSString *str) { 23 | self.textLabel.text = [NSString stringWithFormat:@"block->%@",str]; 24 | } withDelegate:self]; 25 | } 26 | return self; 27 | } 28 | -(void)response:(NSString *)str 29 | { 30 | self.textLabel.text = [NSString stringWithFormat:@"delegate->%@",str];; 31 | } 32 | 33 | -(void)dealloc 34 | { 35 | [[DelegateShare shareInstance] removeObserver:self]; 36 | } 37 | @end 38 | -------------------------------------------------------------------------------- /多代理/DelegateShare.h: -------------------------------------------------------------------------------- 1 | // 2 | // DelegateShare.h 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @protocol DelegateShareDelegate 13 | 14 | - (void)response:(NSString *)str; 15 | 16 | @end 17 | @interface DelegateShare : NSObject 18 | + (DelegateShare *)shareInstance; 19 | // 多代理 使用 20 | @property (nonatomic, assign) id delegate; 21 | //测试 使用 标示是否 是用block 方式 22 | @property (nonatomic, assign) BOOL isBlock; 23 | //添加 block 监听, delegate 作为 观察者,不需要时 可移除 24 | - (void)observer:(void (^)(NSString *str))sumBlok withDelegate:(id)delegate; 25 | //移除 block 监听 26 | - (void)removeObserver:(id)delegate; 27 | 28 | 29 | #pragma mark - 触发多代理 30 | - (void)changeString:(NSString *)str; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /多代理/DelegateShare.m: -------------------------------------------------------------------------------- 1 | // 2 | // DelegateShare.m 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import "DelegateShare.h" 10 | #import 11 | 12 | 13 | typedef void (^dataBlock)(NSString * data); 14 | @interface DelegateShare () 15 | @property (nonatomic, strong) NSMutableDictionary* delegateCache; 16 | @property (nonatomic, strong) NSPointerArray *weakRefTargets; 17 | @property (nonatomic, strong) NSMutableDictionary* blocks; 18 | @property (nonatomic, copy) void (^block)(NSString * str); 19 | @end 20 | @implementation DelegateShare 21 | + (DelegateShare *)shareInstance 22 | { 23 | static DelegateShare * share; 24 | static dispatch_once_t onceToken; 25 | dispatch_once(&onceToken, ^{ 26 | share = [DelegateShare new]; 27 | }); 28 | return share; 29 | } 30 | -(NSMutableDictionary *)delegateCache 31 | { 32 | if (_delegateCache) { 33 | _delegateCache = [NSMutableDictionary dictionary]; 34 | } 35 | return _delegateCache; 36 | } 37 | -(NSMutableDictionary *)blocks 38 | { 39 | if (!_blocks) { 40 | _blocks = [NSMutableDictionary dictionary]; 41 | } 42 | return _blocks; 43 | } 44 | -(NSPointerArray *)weakRefTargets 45 | { 46 | if (!_weakRefTargets) { 47 | _weakRefTargets = [NSPointerArray weakObjectsPointerArray]; 48 | } 49 | return _weakRefTargets; 50 | } 51 | #pragma mark - 多 block 传递 52 | /** 53 | * 添加监听 54 | * 55 | */ 56 | - (void)observer:(void (^)(NSString *str))sumBlok withDelegate:(id)delegate 57 | { 58 | NSObject* obj = (NSObject*)delegate; 59 | if (sumBlok && delegate) { 60 | [self.blocks setObject:sumBlok forKey:[NSString stringWithFormat:@"%lu", (unsigned long)obj.hash]]; 61 | } 62 | else { 63 | NSLog(@"参数不能为空!"); 64 | } 65 | } 66 | /** 67 | * 移除监听 68 | */ 69 | - (void)removeObserver:(id)delegate 70 | { 71 | if (delegate) { 72 | NSObject* obj = (NSObject*)delegate; 73 | 74 | [self.blocks removeObjectForKey:[NSString stringWithFormat:@"%lu", (unsigned long)obj.hash]]; 75 | NSLog(@"---->%@ 已移除", delegate); 76 | } 77 | } 78 | 79 | #pragma mark - 多代理 80 | -(void)setDelegate:(id)delegate 81 | { 82 | if ([delegate respondsToSelector:@selector(response:)]) { 83 | [self.weakRefTargets addPointer:(__bridge void *)delegate]; 84 | } 85 | } 86 | 87 | - (void)changeString:(NSString *)str 88 | { 89 | if (_isBlock) { 90 | for (dataBlock block in self.blocks.allValues) { 91 | if (block) { 92 | block(str); 93 | } 94 | } 95 | } 96 | else{ 97 | for (id target in self.weakRefTargets) { 98 | if ([target respondsToSelector:@selector(response:)]) { 99 | [target response:str]; 100 | } 101 | } 102 | } 103 | 104 | } 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /多代理/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /多代理/SecondViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 6/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SecondViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /多代理/SecondViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 6/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import "SecondViewController.h" 10 | 11 | #import "DelegateShare.h" 12 | @interface SecondViewController () 13 | @property (weak, nonatomic) IBOutlet UITextField *textField; 14 | @property (weak, nonatomic) IBOutlet UILabel *label; 15 | 16 | @end 17 | 18 | @implementation SecondViewController 19 | { 20 | DelegateShare * delegate; 21 | } 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | delegate = [DelegateShare shareInstance]; 25 | delegate.delegate = self; 26 | // Do any additional setup after loading the view. 27 | } 28 | //代理触发 29 | -(void)response:(NSString *)str 30 | { 31 | 32 | _label.text = str; 33 | } 34 | - (IBAction)btnDidAction:(id)sender { 35 | //触发 代理事件 36 | [delegate changeString:_textField.text]; 37 | } 38 | - (IBAction)dismiss:(id)sender { 39 | [self dismissViewControllerAnimated:YES completion:nil]; 40 | } 41 | 42 | /* 43 | #pragma mark - Navigation 44 | 45 | // In a storyboard-based application, you will often want to do a little preparation before navigation 46 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 47 | // Get the new view controller using [segue destinationViewController]. 48 | // Pass the selected object to the new view controller. 49 | } 50 | */ 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /多代理/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /多代理/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import "CustomTableViewCell.h" 10 | #import "ViewController.h" 11 | @interface ViewController () 12 | 13 | @property (weak, nonatomic) IBOutlet UITextField* textField; 14 | @property (weak, nonatomic) IBOutlet UITableView* tableView; 15 | @property (nonatomic, strong) DelegateShare* shareDelegate; 16 | @property (weak, nonatomic) IBOutlet UISwitch* switchBtn; 17 | 18 | @end 19 | 20 | @implementation ViewController 21 | - (DelegateShare*)shareDelegate 22 | { 23 | if (!_shareDelegate) { 24 | _shareDelegate = [DelegateShare shareInstance]; 25 | } 26 | return _shareDelegate; 27 | } 28 | - (void)viewDidLoad 29 | { 30 | [super viewDidLoad]; 31 | self.shareDelegate.delegate = self; 32 | // Do any additional setup after loading the view, typically from a nib. 33 | } 34 | 35 | - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section 36 | { 37 | return 10; 38 | } 39 | 40 | - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 41 | { 42 | CustomTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"customcell"]; 43 | if (!cell) { 44 | cell = [[CustomTableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"customcell"]; 45 | } 46 | self.shareDelegate.delegate = cell; 47 | return cell; 48 | } 49 | 50 | - (void)response:(NSString*)str 51 | { 52 | NSLog(@"class->%@",[self class]); 53 | } 54 | 55 | - (IBAction)cwitchChangeAction:(id)sender 56 | { 57 | self.shareDelegate.isBlock = !_switchBtn.on; 58 | } 59 | 60 | - (IBAction)btnDidAction:(id)sender 61 | { 62 | //触发 代理事件 63 | [self.shareDelegate changeString:_textField.text]; 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /多代理/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 多代理 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /多代理Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /多代理Tests/___Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ___Tests.m 3 | // 多代理Tests 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ___Tests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation ___Tests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /多代理UITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /多代理UITests/___UITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ___UITests.m 3 | // 多代理UITests 4 | // 5 | // Created by 邴天宇 on 5/4/16. 6 | // Copyright © 2016年 邴天宇. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ___UITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation ___UITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------