├── CDPSearchController ├── CDPSearchController.h └── CDPSearchController.m ├── README.md ├── gif.gif ├── searchController.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── CDP.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── searchController.xcscheme │ └── xcschememanagement.plist ├── searchController ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── CDPSearchModel.h ├── CDPSearchModel.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── searchControllerTests ├── Info.plist └── searchControllerTests.m /CDPSearchController/CDPSearchController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDPSearchController.h 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface CDPSearchController : NSObject 13 | 14 | //搜索标题 15 | @property (nonatomic,copy) NSString *prompt; 16 | 17 | //搜索栏为空时默认显示的灰色字 18 | @property (nonatomic,copy) NSString *placeholder; 19 | 20 | //搜索结果数组,用来刷新显示搜索结果 21 | @property (nonatomic,strong) NSMutableArray *searchResultArr; 22 | 23 | //搜索参数数组 24 | @property (nonatomic,strong) NSArray *parameterArr; 25 | 26 | //搜索时的tableView 27 | @property (nonatomic,strong) UITableView *searchTableView; 28 | 29 | //初始化 30 | //第一个参数填写调用CDPSearchController的controller,且需要遵守tableView的协议 31 | //第二个参数填写总数据源 32 | //第三个参数填写搜索标题 33 | //第四个参数填写搜索栏为空时默认显示的灰色字 34 | //第五个参数填写model中所要搜索的相关参数名数组 35 | -(id)initWithController:(UIViewController *)controller dataArr:(NSArray *)dataArr prompt:(NSString *)prompt placeholder:(NSString *)placeholder parameterArr:(NSArray *)parameterArr; 36 | 37 | 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CDPSearchController/CDPSearchController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CDPSearchController.m 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. All rights reserved. 7 | // 8 | 9 | #import "CDPSearchController.h" 10 | 11 | @implementation CDPSearchController{ 12 | UIViewController *_controller;//调用CDPSearchController的controller 13 | 14 | UITableViewController *_tableViewController;//显示搜索结果的tableView 15 | UISearchController *_searchController;//searchController 16 | 17 | NSArray *_dataArr;//总数据源 18 | 19 | NSMutableString *_predicateStr;//谓词语句 20 | } 21 | 22 | //初始化 23 | -(id)initWithController:(UIViewController *)controller dataArr:(NSArray *)dataArr prompt:(NSString *)prompt placeholder:(NSString *)placeholder parameterArr:(NSArray *)parameterArr{ 24 | if (self=[super init]) { 25 | _controller=controller; 26 | _prompt=prompt; 27 | _placeholder=placeholder; 28 | _parameterArr=parameterArr; 29 | _dataArr=[[NSArray alloc] initWithArray:dataArr]; 30 | _searchResultArr=[[NSMutableArray alloc] init]; 31 | _predicateStr=[[NSMutableString alloc] init]; 32 | 33 | 34 | _tableViewController=[[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; 35 | _tableViewController.tableView.tableFooterView=[[UIView alloc] initWithFrame:CGRectZero]; 36 | _searchTableView=_tableViewController.tableView; 37 | _tableViewController.tableView.delegate=controller; 38 | _tableViewController.tableView.dataSource=controller; 39 | 40 | _searchController=[[UISearchController alloc] initWithSearchResultsController:_tableViewController]; 41 | _searchController.searchResultsUpdater=self; 42 | _searchController.searchBar.prompt=_prompt; 43 | _searchController.searchBar.placeholder=_placeholder; 44 | 45 | [_controller presentViewController:_searchController animated:YES completion:nil]; 46 | } 47 | 48 | return self; 49 | } 50 | //设置搜索标题 51 | -(void)setPrompt:(NSString *)prompt{ 52 | _prompt=prompt; 53 | _searchController.searchBar.prompt=_prompt; 54 | } 55 | //设置搜索栏为空时默认显示的灰色字 56 | -(void)setPlaceholder:(NSString *)placeholder{ 57 | _placeholder=placeholder; 58 | _searchController.searchBar.placeholder=_placeholder; 59 | } 60 | #pragma mark - UISearchResultsUpdating监听者搜索框中的值的变化 61 | 62 | -(void)updateSearchResultsForSearchController:(UISearchController *)searchController{ 63 | 64 | NSString *searchStr = searchController.searchBar.text; 65 | 66 | _predicateStr=[NSMutableString stringWithFormat:@""]; 67 | 68 | for (NSString *parameterStr in _parameterArr) { 69 | [_predicateStr appendString:[NSString stringWithFormat:@"self.%@ CONTAINS [CD] '%@' OR ",parameterStr,searchStr]]; 70 | } 71 | 72 | [_predicateStr deleteCharactersInRange:NSMakeRange(_predicateStr.length-4,4)]; 73 | 74 | NSPredicate *predicate = [NSPredicate predicateWithFormat:_predicateStr]; 75 | 76 | _searchResultArr = [NSMutableArray arrayWithArray:[_dataArr filteredArrayUsingPredicate:predicate]]; 77 | 78 | [_tableViewController.tableView reloadData]; 79 | } 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CDPSearchController 2 | CDPSearchController package, can realize model data search and display,more details will be in demo. 3 | 4 | And the iOS version should be >= 8.0. 5 | 6 | 7 | ![image](https://github.com/cdpenggod/CDPSearchController/blob/master/gif.gif) 8 | -------------------------------------------------------------------------------- /gif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdpenggod/CDPSearchController/353f55119c234f9836f88af09fc6f3199d3650e0/gif.gif -------------------------------------------------------------------------------- /searchController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5E6A2F5A1B0463390014511F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E6A2F591B0463390014511F /* main.m */; }; 11 | 5E6A2F5D1B0463390014511F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E6A2F5C1B0463390014511F /* AppDelegate.m */; }; 12 | 5E6A2F601B0463390014511F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E6A2F5F1B0463390014511F /* ViewController.m */; }; 13 | 5E6A2F631B0463390014511F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5E6A2F611B0463390014511F /* Main.storyboard */; }; 14 | 5E6A2F651B0463390014511F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E6A2F641B0463390014511F /* Images.xcassets */; }; 15 | 5E6A2F681B0463390014511F /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5E6A2F661B0463390014511F /* LaunchScreen.xib */; }; 16 | 5E6A2F741B0463390014511F /* searchControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E6A2F731B0463390014511F /* searchControllerTests.m */; }; 17 | 5E6A2F7F1B0466180014511F /* CDPSearchModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E6A2F7E1B0466180014511F /* CDPSearchModel.m */; }; 18 | 5E6A2F861B047D680014511F /* CDPSearchController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E6A2F851B047D680014511F /* CDPSearchController.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 5E6A2F6E1B0463390014511F /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 5E6A2F4C1B0463390014511F /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 5E6A2F531B0463390014511F; 27 | remoteInfo = searchController; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 5E6A2F541B0463390014511F /* searchController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = searchController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 5E6A2F581B0463390014511F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 5E6A2F591B0463390014511F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | 5E6A2F5B1B0463390014511F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 36 | 5E6A2F5C1B0463390014511F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 37 | 5E6A2F5E1B0463390014511F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 38 | 5E6A2F5F1B0463390014511F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 39 | 5E6A2F621B0463390014511F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 40 | 5E6A2F641B0463390014511F /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 41 | 5E6A2F671B0463390014511F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 42 | 5E6A2F6D1B0463390014511F /* searchControllerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = searchControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 5E6A2F721B0463390014511F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | 5E6A2F731B0463390014511F /* searchControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = searchControllerTests.m; sourceTree = ""; }; 45 | 5E6A2F7D1B0466180014511F /* CDPSearchModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDPSearchModel.h; sourceTree = ""; }; 46 | 5E6A2F7E1B0466180014511F /* CDPSearchModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDPSearchModel.m; sourceTree = ""; }; 47 | 5E6A2F841B047D680014511F /* CDPSearchController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDPSearchController.h; sourceTree = ""; }; 48 | 5E6A2F851B047D680014511F /* CDPSearchController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDPSearchController.m; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | 5E6A2F511B0463390014511F /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | 5E6A2F6A1B0463390014511F /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 5E6A2F4B1B0463390014511F = { 70 | isa = PBXGroup; 71 | children = ( 72 | 5E6A2F801B047BCA0014511F /* CDPSearchController */, 73 | 5E6A2F561B0463390014511F /* searchController */, 74 | 5E6A2F701B0463390014511F /* searchControllerTests */, 75 | 5E6A2F551B0463390014511F /* Products */, 76 | ); 77 | sourceTree = ""; 78 | }; 79 | 5E6A2F551B0463390014511F /* Products */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 5E6A2F541B0463390014511F /* searchController.app */, 83 | 5E6A2F6D1B0463390014511F /* searchControllerTests.xctest */, 84 | ); 85 | name = Products; 86 | sourceTree = ""; 87 | }; 88 | 5E6A2F561B0463390014511F /* searchController */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 5E6A2F5B1B0463390014511F /* AppDelegate.h */, 92 | 5E6A2F5C1B0463390014511F /* AppDelegate.m */, 93 | 5E6A2F5E1B0463390014511F /* ViewController.h */, 94 | 5E6A2F5F1B0463390014511F /* ViewController.m */, 95 | 5E6A2F7D1B0466180014511F /* CDPSearchModel.h */, 96 | 5E6A2F7E1B0466180014511F /* CDPSearchModel.m */, 97 | 5E6A2F611B0463390014511F /* Main.storyboard */, 98 | 5E6A2F641B0463390014511F /* Images.xcassets */, 99 | 5E6A2F661B0463390014511F /* LaunchScreen.xib */, 100 | 5E6A2F571B0463390014511F /* Supporting Files */, 101 | ); 102 | path = searchController; 103 | sourceTree = ""; 104 | }; 105 | 5E6A2F571B0463390014511F /* Supporting Files */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 5E6A2F581B0463390014511F /* Info.plist */, 109 | 5E6A2F591B0463390014511F /* main.m */, 110 | ); 111 | name = "Supporting Files"; 112 | sourceTree = ""; 113 | }; 114 | 5E6A2F701B0463390014511F /* searchControllerTests */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 5E6A2F731B0463390014511F /* searchControllerTests.m */, 118 | 5E6A2F711B0463390014511F /* Supporting Files */, 119 | ); 120 | path = searchControllerTests; 121 | sourceTree = ""; 122 | }; 123 | 5E6A2F711B0463390014511F /* Supporting Files */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | 5E6A2F721B0463390014511F /* Info.plist */, 127 | ); 128 | name = "Supporting Files"; 129 | sourceTree = ""; 130 | }; 131 | 5E6A2F801B047BCA0014511F /* CDPSearchController */ = { 132 | isa = PBXGroup; 133 | children = ( 134 | 5E6A2F841B047D680014511F /* CDPSearchController.h */, 135 | 5E6A2F851B047D680014511F /* CDPSearchController.m */, 136 | ); 137 | path = CDPSearchController; 138 | sourceTree = ""; 139 | }; 140 | /* End PBXGroup section */ 141 | 142 | /* Begin PBXNativeTarget section */ 143 | 5E6A2F531B0463390014511F /* searchController */ = { 144 | isa = PBXNativeTarget; 145 | buildConfigurationList = 5E6A2F771B0463390014511F /* Build configuration list for PBXNativeTarget "searchController" */; 146 | buildPhases = ( 147 | 5E6A2F501B0463390014511F /* Sources */, 148 | 5E6A2F511B0463390014511F /* Frameworks */, 149 | 5E6A2F521B0463390014511F /* Resources */, 150 | ); 151 | buildRules = ( 152 | ); 153 | dependencies = ( 154 | ); 155 | name = searchController; 156 | productName = searchController; 157 | productReference = 5E6A2F541B0463390014511F /* searchController.app */; 158 | productType = "com.apple.product-type.application"; 159 | }; 160 | 5E6A2F6C1B0463390014511F /* searchControllerTests */ = { 161 | isa = PBXNativeTarget; 162 | buildConfigurationList = 5E6A2F7A1B0463390014511F /* Build configuration list for PBXNativeTarget "searchControllerTests" */; 163 | buildPhases = ( 164 | 5E6A2F691B0463390014511F /* Sources */, 165 | 5E6A2F6A1B0463390014511F /* Frameworks */, 166 | 5E6A2F6B1B0463390014511F /* Resources */, 167 | ); 168 | buildRules = ( 169 | ); 170 | dependencies = ( 171 | 5E6A2F6F1B0463390014511F /* PBXTargetDependency */, 172 | ); 173 | name = searchControllerTests; 174 | productName = searchControllerTests; 175 | productReference = 5E6A2F6D1B0463390014511F /* searchControllerTests.xctest */; 176 | productType = "com.apple.product-type.bundle.unit-test"; 177 | }; 178 | /* End PBXNativeTarget section */ 179 | 180 | /* Begin PBXProject section */ 181 | 5E6A2F4C1B0463390014511F /* Project object */ = { 182 | isa = PBXProject; 183 | attributes = { 184 | LastUpgradeCheck = 0630; 185 | ORGANIZATIONNAME = CDP; 186 | TargetAttributes = { 187 | 5E6A2F531B0463390014511F = { 188 | CreatedOnToolsVersion = 6.3.1; 189 | }; 190 | 5E6A2F6C1B0463390014511F = { 191 | CreatedOnToolsVersion = 6.3.1; 192 | TestTargetID = 5E6A2F531B0463390014511F; 193 | }; 194 | }; 195 | }; 196 | buildConfigurationList = 5E6A2F4F1B0463390014511F /* Build configuration list for PBXProject "searchController" */; 197 | compatibilityVersion = "Xcode 3.2"; 198 | developmentRegion = English; 199 | hasScannedForEncodings = 0; 200 | knownRegions = ( 201 | en, 202 | Base, 203 | ); 204 | mainGroup = 5E6A2F4B1B0463390014511F; 205 | productRefGroup = 5E6A2F551B0463390014511F /* Products */; 206 | projectDirPath = ""; 207 | projectRoot = ""; 208 | targets = ( 209 | 5E6A2F531B0463390014511F /* searchController */, 210 | 5E6A2F6C1B0463390014511F /* searchControllerTests */, 211 | ); 212 | }; 213 | /* End PBXProject section */ 214 | 215 | /* Begin PBXResourcesBuildPhase section */ 216 | 5E6A2F521B0463390014511F /* Resources */ = { 217 | isa = PBXResourcesBuildPhase; 218 | buildActionMask = 2147483647; 219 | files = ( 220 | 5E6A2F631B0463390014511F /* Main.storyboard in Resources */, 221 | 5E6A2F681B0463390014511F /* LaunchScreen.xib in Resources */, 222 | 5E6A2F651B0463390014511F /* Images.xcassets in Resources */, 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | }; 226 | 5E6A2F6B1B0463390014511F /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | /* End PBXResourcesBuildPhase section */ 234 | 235 | /* Begin PBXSourcesBuildPhase section */ 236 | 5E6A2F501B0463390014511F /* Sources */ = { 237 | isa = PBXSourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | 5E6A2F601B0463390014511F /* ViewController.m in Sources */, 241 | 5E6A2F7F1B0466180014511F /* CDPSearchModel.m in Sources */, 242 | 5E6A2F861B047D680014511F /* CDPSearchController.m in Sources */, 243 | 5E6A2F5D1B0463390014511F /* AppDelegate.m in Sources */, 244 | 5E6A2F5A1B0463390014511F /* main.m in Sources */, 245 | ); 246 | runOnlyForDeploymentPostprocessing = 0; 247 | }; 248 | 5E6A2F691B0463390014511F /* Sources */ = { 249 | isa = PBXSourcesBuildPhase; 250 | buildActionMask = 2147483647; 251 | files = ( 252 | 5E6A2F741B0463390014511F /* searchControllerTests.m in Sources */, 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | /* End PBXSourcesBuildPhase section */ 257 | 258 | /* Begin PBXTargetDependency section */ 259 | 5E6A2F6F1B0463390014511F /* PBXTargetDependency */ = { 260 | isa = PBXTargetDependency; 261 | target = 5E6A2F531B0463390014511F /* searchController */; 262 | targetProxy = 5E6A2F6E1B0463390014511F /* PBXContainerItemProxy */; 263 | }; 264 | /* End PBXTargetDependency section */ 265 | 266 | /* Begin PBXVariantGroup section */ 267 | 5E6A2F611B0463390014511F /* Main.storyboard */ = { 268 | isa = PBXVariantGroup; 269 | children = ( 270 | 5E6A2F621B0463390014511F /* Base */, 271 | ); 272 | name = Main.storyboard; 273 | sourceTree = ""; 274 | }; 275 | 5E6A2F661B0463390014511F /* LaunchScreen.xib */ = { 276 | isa = PBXVariantGroup; 277 | children = ( 278 | 5E6A2F671B0463390014511F /* Base */, 279 | ); 280 | name = LaunchScreen.xib; 281 | sourceTree = ""; 282 | }; 283 | /* End PBXVariantGroup section */ 284 | 285 | /* Begin XCBuildConfiguration section */ 286 | 5E6A2F751B0463390014511F /* Debug */ = { 287 | isa = XCBuildConfiguration; 288 | buildSettings = { 289 | ALWAYS_SEARCH_USER_PATHS = NO; 290 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 291 | CLANG_CXX_LIBRARY = "libc++"; 292 | CLANG_ENABLE_MODULES = YES; 293 | CLANG_ENABLE_OBJC_ARC = YES; 294 | CLANG_WARN_BOOL_CONVERSION = YES; 295 | CLANG_WARN_CONSTANT_CONVERSION = YES; 296 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 297 | CLANG_WARN_EMPTY_BODY = YES; 298 | CLANG_WARN_ENUM_CONVERSION = YES; 299 | CLANG_WARN_INT_CONVERSION = YES; 300 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 301 | CLANG_WARN_UNREACHABLE_CODE = YES; 302 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 303 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 304 | COPY_PHASE_STRIP = NO; 305 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 306 | ENABLE_STRICT_OBJC_MSGSEND = YES; 307 | GCC_C_LANGUAGE_STANDARD = gnu99; 308 | GCC_DYNAMIC_NO_PIC = NO; 309 | GCC_NO_COMMON_BLOCKS = YES; 310 | GCC_OPTIMIZATION_LEVEL = 0; 311 | GCC_PREPROCESSOR_DEFINITIONS = ( 312 | "DEBUG=1", 313 | "$(inherited)", 314 | ); 315 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 316 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 317 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 318 | GCC_WARN_UNDECLARED_SELECTOR = YES; 319 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 320 | GCC_WARN_UNUSED_FUNCTION = YES; 321 | GCC_WARN_UNUSED_VARIABLE = YES; 322 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 323 | MTL_ENABLE_DEBUG_INFO = YES; 324 | ONLY_ACTIVE_ARCH = YES; 325 | SDKROOT = iphoneos; 326 | TARGETED_DEVICE_FAMILY = "1,2"; 327 | }; 328 | name = Debug; 329 | }; 330 | 5E6A2F761B0463390014511F /* Release */ = { 331 | isa = XCBuildConfiguration; 332 | buildSettings = { 333 | ALWAYS_SEARCH_USER_PATHS = NO; 334 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 335 | CLANG_CXX_LIBRARY = "libc++"; 336 | CLANG_ENABLE_MODULES = YES; 337 | CLANG_ENABLE_OBJC_ARC = YES; 338 | CLANG_WARN_BOOL_CONVERSION = YES; 339 | CLANG_WARN_CONSTANT_CONVERSION = YES; 340 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 341 | CLANG_WARN_EMPTY_BODY = YES; 342 | CLANG_WARN_ENUM_CONVERSION = YES; 343 | CLANG_WARN_INT_CONVERSION = YES; 344 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 345 | CLANG_WARN_UNREACHABLE_CODE = YES; 346 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 347 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 348 | COPY_PHASE_STRIP = NO; 349 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 350 | ENABLE_NS_ASSERTIONS = NO; 351 | ENABLE_STRICT_OBJC_MSGSEND = YES; 352 | GCC_C_LANGUAGE_STANDARD = gnu99; 353 | GCC_NO_COMMON_BLOCKS = YES; 354 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 355 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 356 | GCC_WARN_UNDECLARED_SELECTOR = YES; 357 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 358 | GCC_WARN_UNUSED_FUNCTION = YES; 359 | GCC_WARN_UNUSED_VARIABLE = YES; 360 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 361 | MTL_ENABLE_DEBUG_INFO = NO; 362 | SDKROOT = iphoneos; 363 | TARGETED_DEVICE_FAMILY = "1,2"; 364 | VALIDATE_PRODUCT = YES; 365 | }; 366 | name = Release; 367 | }; 368 | 5E6A2F781B0463390014511F /* Debug */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 372 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 373 | INFOPLIST_FILE = searchController/Info.plist; 374 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 375 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 376 | PRODUCT_NAME = "$(TARGET_NAME)"; 377 | }; 378 | name = Debug; 379 | }; 380 | 5E6A2F791B0463390014511F /* Release */ = { 381 | isa = XCBuildConfiguration; 382 | buildSettings = { 383 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 384 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 385 | INFOPLIST_FILE = searchController/Info.plist; 386 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 387 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 388 | PRODUCT_NAME = "$(TARGET_NAME)"; 389 | }; 390 | name = Release; 391 | }; 392 | 5E6A2F7B1B0463390014511F /* Debug */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | BUNDLE_LOADER = "$(TEST_HOST)"; 396 | FRAMEWORK_SEARCH_PATHS = ( 397 | "$(SDKROOT)/Developer/Library/Frameworks", 398 | "$(inherited)", 399 | ); 400 | GCC_PREPROCESSOR_DEFINITIONS = ( 401 | "DEBUG=1", 402 | "$(inherited)", 403 | ); 404 | INFOPLIST_FILE = searchControllerTests/Info.plist; 405 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 406 | PRODUCT_NAME = "$(TARGET_NAME)"; 407 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/searchController.app/searchController"; 408 | }; 409 | name = Debug; 410 | }; 411 | 5E6A2F7C1B0463390014511F /* Release */ = { 412 | isa = XCBuildConfiguration; 413 | buildSettings = { 414 | BUNDLE_LOADER = "$(TEST_HOST)"; 415 | FRAMEWORK_SEARCH_PATHS = ( 416 | "$(SDKROOT)/Developer/Library/Frameworks", 417 | "$(inherited)", 418 | ); 419 | INFOPLIST_FILE = searchControllerTests/Info.plist; 420 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 421 | PRODUCT_NAME = "$(TARGET_NAME)"; 422 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/searchController.app/searchController"; 423 | }; 424 | name = Release; 425 | }; 426 | /* End XCBuildConfiguration section */ 427 | 428 | /* Begin XCConfigurationList section */ 429 | 5E6A2F4F1B0463390014511F /* Build configuration list for PBXProject "searchController" */ = { 430 | isa = XCConfigurationList; 431 | buildConfigurations = ( 432 | 5E6A2F751B0463390014511F /* Debug */, 433 | 5E6A2F761B0463390014511F /* Release */, 434 | ); 435 | defaultConfigurationIsVisible = 0; 436 | defaultConfigurationName = Release; 437 | }; 438 | 5E6A2F771B0463390014511F /* Build configuration list for PBXNativeTarget "searchController" */ = { 439 | isa = XCConfigurationList; 440 | buildConfigurations = ( 441 | 5E6A2F781B0463390014511F /* Debug */, 442 | 5E6A2F791B0463390014511F /* Release */, 443 | ); 444 | defaultConfigurationIsVisible = 0; 445 | }; 446 | 5E6A2F7A1B0463390014511F /* Build configuration list for PBXNativeTarget "searchControllerTests" */ = { 447 | isa = XCConfigurationList; 448 | buildConfigurations = ( 449 | 5E6A2F7B1B0463390014511F /* Debug */, 450 | 5E6A2F7C1B0463390014511F /* Release */, 451 | ); 452 | defaultConfigurationIsVisible = 0; 453 | }; 454 | /* End XCConfigurationList section */ 455 | }; 456 | rootObject = 5E6A2F4C1B0463390014511F /* Project object */; 457 | } 458 | -------------------------------------------------------------------------------- /searchController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /searchController.xcodeproj/xcuserdata/CDP.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /searchController.xcodeproj/xcuserdata/CDP.xcuserdatad/xcschemes/searchController.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /searchController.xcodeproj/xcuserdata/CDP.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | searchController.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 5E6A2F531B0463390014511F 16 | 17 | primary 18 | 19 | 20 | 5E6A2F6C1B0463390014511F 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /searchController/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. 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 | -------------------------------------------------------------------------------- /searchController/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. 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 | -------------------------------------------------------------------------------- /searchController/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /searchController/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 | -------------------------------------------------------------------------------- /searchController/CDPSearchModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDPSearchModel.h 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CDPSearchModel : NSObject 12 | 13 | @property (nonatomic,strong) NSString *nameStr;//姓名 14 | 15 | @property (nonatomic,strong) NSString *phoneStr;//电话 16 | 17 | @property (nonatomic,strong) NSString *signStr;//签名 18 | 19 | //初始化 20 | -(id)initWithNameStr:(NSString *)name andPhoneStr:(NSString *)phone signStr:(NSString *)sign; 21 | 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /searchController/CDPSearchModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // CDPSearchModel.m 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. All rights reserved. 7 | // 8 | 9 | #import "CDPSearchModel.h" 10 | 11 | @implementation CDPSearchModel 12 | 13 | //初始化 14 | -(id)initWithNameStr:(NSString *)name andPhoneStr:(NSString *)phone signStr:(NSString *)sign{ 15 | if (self=[super init]) { 16 | _nameStr=name; 17 | _phoneStr=phone; 18 | _signStr=sign; 19 | 20 | } 21 | return self; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /searchController/Images.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 | } -------------------------------------------------------------------------------- /searchController/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "ipad", 6 | "minimum-system-version" : "7.0", 7 | "extent" : "full-screen", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "landscape", 12 | "idiom" : "ipad", 13 | "minimum-system-version" : "7.0", 14 | "extent" : "full-screen", 15 | "scale" : "1x" 16 | }, 17 | { 18 | "orientation" : "landscape", 19 | "idiom" : "ipad", 20 | "minimum-system-version" : "7.0", 21 | "extent" : "full-screen", 22 | "scale" : "2x" 23 | }, 24 | { 25 | "orientation" : "portrait", 26 | "idiom" : "iphone", 27 | "minimum-system-version" : "7.0", 28 | "scale" : "2x" 29 | }, 30 | { 31 | "orientation" : "portrait", 32 | "idiom" : "iphone", 33 | "minimum-system-version" : "7.0", 34 | "subtype" : "retina4", 35 | "scale" : "2x" 36 | }, 37 | { 38 | "orientation" : "portrait", 39 | "idiom" : "ipad", 40 | "minimum-system-version" : "7.0", 41 | "extent" : "full-screen", 42 | "scale" : "1x" 43 | } 44 | ], 45 | "info" : { 46 | "version" : 1, 47 | "author" : "xcode" 48 | } 49 | } -------------------------------------------------------------------------------- /searchController/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | CDP.$(PRODUCT_NAME:rfc1034identifier) 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 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /searchController/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /searchController/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "CDPSearchModel.h" 12 | 13 | #import "CDPSearchController.h"//引入头文件 14 | 15 | //CDPSearchController适用于iOS8.0及以上 16 | 17 | //调用CDPSearchController的controller需要遵守以下tableView的协议 18 | 19 | @interface ViewController () { 20 | NSMutableArray *_dataArr;//数据源 21 | UITableView *_tableView; 22 | 23 | CDPSearchController *_searchController; 24 | } 25 | 26 | @end 27 | 28 | @implementation ViewController 29 | 30 | - (void)viewDidLoad { 31 | [super viewDidLoad]; 32 | self.view.backgroundColor=[UIColor lightGrayColor]; 33 | self.automaticallyAdjustsScrollViewInsets=NO; 34 | 35 | 36 | [self creatData]; 37 | 38 | [self creatUI]; 39 | 40 | } 41 | #pragma mark 创建Data和UI 42 | //创建Data 43 | -(void)creatData{ 44 | CDPSearchModel *model1=[[CDPSearchModel alloc] initWithNameStr:@"王二货" andPhoneStr:@"13119491824" signStr:@"我只是个二货"]; 45 | 46 | CDPSearchModel *model2=[[CDPSearchModel alloc] initWithNameStr:@"李四" andPhoneStr:@"13119412312" signStr:@"李四就是我"]; 47 | 48 | CDPSearchModel *model3=[[CDPSearchModel alloc] initWithNameStr:@"菲菲" andPhoneStr:@"13119493421" signStr:@"额。。。"]; 49 | 50 | CDPSearchModel *model4=[[CDPSearchModel alloc] initWithNameStr:@"女神经" andPhoneStr:@"13217491814" signStr:@"女汉子"]; 51 | 52 | CDPSearchModel *model5=[[CDPSearchModel alloc] initWithNameStr:@"王小二" andPhoneStr:@"13115137224" signStr:@"小二哥"]; 53 | 54 | CDPSearchModel *model6=[[CDPSearchModel alloc] initWithNameStr:@"ccToday" andPhoneStr:@"13819444824" signStr:@"gogoggo"]; 55 | 56 | CDPSearchModel *model7=[[CDPSearchModel alloc] initWithNameStr:@"美美" andPhoneStr:@"13222491824" signStr:@"我去"]; 57 | 58 | CDPSearchModel *model8=[[CDPSearchModel alloc] initWithNameStr:@"疯子d" andPhoneStr:@"13937182412" signStr:@"疯疯疯"]; 59 | 60 | CDPSearchModel *model9=[[CDPSearchModel alloc] initWithNameStr:@"LEO" andPhoneStr:@"18231255123" signStr:@"LLLLL"]; 61 | 62 | CDPSearchModel *model10=[[CDPSearchModel alloc] initWithNameStr:@"女" andPhoneStr:@"18431266123" signStr:@"女L"]; 63 | 64 | CDPSearchModel *model11=[[CDPSearchModel alloc] initWithNameStr:@"男" andPhoneStr:@"18928171241" signStr:@"男男"]; 65 | 66 | 67 | //创建数据源 68 | _dataArr=[[NSMutableArray alloc] initWithObjects:model1,model2,model3,model4,model5,model6,model7,model8,model9,model10,model11,nil]; 69 | 70 | 71 | } 72 | //创建UI 73 | -(void)creatUI{ 74 | //搜索按钮 75 | UIButton *searchButton=[[UIButton alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/2-20,20,40,27)]; 76 | searchButton.backgroundColor=[UIColor whiteColor]; 77 | [searchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 78 | [searchButton setTitle:@"搜索" forState:UIControlStateNormal]; 79 | [searchButton addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside]; 80 | [self.view addSubview:searchButton]; 81 | 82 | //tableView 83 | _tableView=[[UITableView alloc] initWithFrame:CGRectMake(0,50,self.view.bounds.size.width,self.view.bounds.size.height-50) style:UITableViewStylePlain]; 84 | _tableView.tableFooterView=[[UIView alloc] initWithFrame:CGRectZero]; 85 | _tableView.delegate=self; 86 | _tableView.dataSource=self; 87 | [self.view addSubview:_tableView]; 88 | } 89 | #pragma mark tableViewDelegate 90 | //行数 91 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 92 | //判断是否搜索tableView 93 | return (tableView==_tableView?_dataArr.count:_searchController.searchResultArr.count); 94 | 95 | } 96 | //行高 97 | -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 98 | return 90; 99 | } 100 | //cell 101 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 102 | UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cdpSearchCell"]; 103 | if (cell==nil) { 104 | cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cdpSearchCell"]; 105 | cell.selectionStyle=UITableViewCellSelectionStyleNone; 106 | cell.textLabel.font=[UIFont systemFontOfSize:15]; 107 | cell.detailTextLabel.font=[UIFont systemFontOfSize:15]; 108 | } 109 | //判断是否搜索tableView 110 | CDPSearchModel *model=(tableView==_tableView?[_dataArr objectAtIndex:indexPath.row]:[_searchController.searchResultArr objectAtIndex:indexPath.row]); 111 | 112 | cell.textLabel.text=[NSString stringWithFormat:@"姓名:%@",model.nameStr]; 113 | cell.detailTextLabel.text=[NSString stringWithFormat:@"电话:%@ 签名:%@",model.phoneStr,model.signStr]; 114 | 115 | return cell; 116 | } 117 | //cell点击 118 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 119 | if (tableView==_tableView) { 120 | UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"不是搜索点击" message:[NSString stringWithFormat:@"点击了第%ld行",(long)indexPath.row] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; 121 | [alertView show]; 122 | } 123 | else{ 124 | UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"搜索点击" message:[NSString stringWithFormat:@"点击了第%ld行",(long)indexPath.row] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; 125 | [alertView show]; 126 | } 127 | 128 | } 129 | 130 | //点击搜索 131 | -(void)searchClick{ 132 | //设置需要搜索的参数名数组,本demo根据CDPSearchModel中的nameStr和phoneStr这两个参数搜索,即姓名和电话 133 | //parameterArr里的参数名必须和model里的参数名一样,否则出错 134 | NSArray *parameterArr=@[@"nameStr",@"phoneStr"]; 135 | 136 | //初始化并设置CDPSearchController 137 | _searchController=[[CDPSearchController alloc] initWithController:self dataArr:_dataArr prompt:@"搜索栏标题" placeholder:@"搜索为空时默认灰色字" parameterArr:parameterArr]; 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 | - (void)didReceiveMemoryWarning { 163 | [super didReceiveMemoryWarning]; 164 | // Dispose of any resources that can be recreated. 165 | } 166 | 167 | @end 168 | -------------------------------------------------------------------------------- /searchController/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // searchController 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. 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 | -------------------------------------------------------------------------------- /searchControllerTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | CDP.$(PRODUCT_NAME:rfc1034identifier) 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 | -------------------------------------------------------------------------------- /searchControllerTests/searchControllerTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // searchControllerTests.m 3 | // searchControllerTests 4 | // 5 | // Created by 柴东鹏 on 15/5/14. 6 | // Copyright (c) 2015年 CDP. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface searchControllerTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation searchControllerTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------