IOS开发搜索和排序(好友列表 通讯录的实现 searchbar)

1 篇文章 0 订阅
1 篇文章 0 订阅

一、效果图:

\\\\

二、概述

 实现一个好友列表,可以分为男女两个选项,并且实现搜索和排序功能。我的数据是放在plist文件中。

三、代码简述

\

代码结构如图,首先自定义一个Cell。

cell.h

01. #import <uikit uikit.h="">
02.  
03. @interface MyCell : UITableViewCell
04.  
05. @property (nonatomic,retain) UIButton *tickButton;
06. @property (nonatomic,retain) UIImageView *selectView;
07. @property (nonatomic,retain) UIImageView *headView;
08. @property (nonatomic,retain) UIImageView *iconImageView;
09. @property (nonatomic,retain) UILabel *nameLabel;
10. @property(nonatomic,retain)  UILabel *signLabel;
11.  
12. - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;
13. - (void)setSelected:(BOOL)selected animated:(BOOL)animated;
14.  
15. @end</uikit>

cell.m

01. #import 'MyCell.h'
02.  
03. @implementation MyCell
04.  
05. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
06. {
07. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
08. if (self) {
09. self.tickButton = [[UIButton alloc]initWithFrame:CGRectMake(11, , 18,19)];
10. [self.tickButton setBackgroundImage:[UIImage imageNamed:@'ic_tick_n.png'] forState:UIControlStateNormal];
11. [self.tickButton setUserInteractionEnabled:NO];
12. self.selectView = [[UIImageView alloc]initWithFrame:CGRectMake(0019,19)];
13. self.selectView.image = [UIImage imageNamed:@'ic_-check_s.png'];
14. self.selectView.hidden = YES;
15. [self.tickButton addSubview:self.selectView];
16. [self.contentView addSubview:self.tickButton];
17.  
18. self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(431432,32)];
19. self.headView.tag = 11;
20. [self.contentView addSubview:self.headView];
21. self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(8020100,17)];
22. self.nameLabel.backgroundColor = [UIColor clearColor];
23. self.nameLabel.textColor = [UIColor colorWithRed:42.0/255.green:42.0/255.blue:42.0/255.alpha:1.0];
24. self.nameLabel.font = [UIFont systemFontOfSize:17];
25. self.nameLabel.numberOfLines = 1;
26. self.nameLabel.tag = 11;
27. [self.contentView addSubview:self.nameLabel];
28. UIImageView *iconImage = [[UIImageView alloc] initWithFrame:CGRectMake(+ , 291717)];
29. iconImage.tag = 13;
30. iconImage.image = [UIImage imageNamed:@'ic_online@2x.png'];
31. [self.contentView addSubview: iconImage];
32.  
33.  
34. self.signLabel = [[UILabel alloc] initWithFrame:CGRectMake(16015120,30)];
35. self.signLabel.numberOfLines = 2;
36. self.signLabel.backgroundColor = [UIColor clearColor];
37. self.signLabel.font = [UIFont systemFontOfSize:15];
38. self.signLabel.textAlignment = NSTextAlignmentCenter;
39. self.signLabel.textColor = [UIColor colorWithRed:156.0/255.green:155.0/255.blue:155.0/255.alpha:1.0];
40. self.signLabel.tag = 14;
41. [self.contentView addSubview:self.signLabel];
42.  
43. UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(059,3201)];
44. [line setImage:[UIImage imageNamed:@'line@2x.png']];
45. [self.contentView addSubview:line];
46. }
47. return self;
48. }
49.  
50. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
51. {
52. [super setSelected:selected animated:animated];
53. if (selected) {
54. [self.selectView setHidden:NO];
55. else {
56. [self.selectView setHidden:YES];
57. }
58.  
59. }
60.  
61. -(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
62. {
63. if(highlighted) {
64. [self.selectView setHighlighted:YES];
65. else {
66. [self.selectView setHighlighted:NO];
67. }
68. }
69.  
70. -(void)dealloc
71. {
72. [self.tickButton release];
73. [self.selectView release];
74. [self.headView release];
75. [self.iconImageView release];
76. [self.nameLabel release];
77. [self.signLabel release];
78. [super dealloc];
79. }
80.  
81. @end

viewController.m

001. #import 'ViewController.h'
002. #import 'MyCell.h'
003. #import 'pinyin.h'
004.  
005. @interface ViewController ()
006.  
007. @end
008.  
009. @implementation ViewController
010.  
011. - (void)viewDidLoad
012. {
013. [super viewDidLoad];
014. [self.view setBackgroundColor:[UIColor colorWithRed:231.0/255.green:231.0/255.blue:231.0/255.alpha:1.0]];
015.  
016. unlimitBtn = [[UIButton alloc]initWithFrame:CGRectMake(62, + 56633)];
017. unlimitBtn.tag = 201;
018. [unlimitBtn setBackgroundImage:[UIImage imageNamed:@'ic_option_lt_n@2x.png'] forState:UIControlStateNormal];
019. [unlimitBtn setBackgroundImage:[UIImage imageNamed:@'ic_option_lt_s@2x.png'] forState:UIControlStateSelected];
020. [unlimitBtn setTitleColor:[UIColor colorWithRed:156.0/255.green:155.0/255.blue:155.0/255.alpha:1.0] forState:UIControlStateNormal];
021. [unlimitBtn setTitleColor:[UIColor colorWithRed:255.0/255.green:255.0/255.blue:255.0/255.alpha:1.0] forState:UIControlStateSelected];
022. [unlimitBtn setTitle:@'不限' forState:UIControlStateNormal];
023. [unlimitBtn addTarget:self  action:@selector(changeTab:) forControlEvents:UIControlEventTouchUpInside];
024. [self.view addSubview:unlimitBtn];
025. unlimitBtn.selected = YES;
026. type = 2;
027.  
028. manBtn = [[UIButton alloc]initWithFrame:CGRectMake(62+66-140+56630)];
029. manBtn.tag = 202;
030. [manBtn setBackgroundImage:[UIImage imageNamed:@'ic_option_mt_n@2x.png'] forState:UIControlStateNormal ];
031. [manBtn setTitleColor:[UIColor colorWithRed:156.0/255.green:155.0/255.blue:155.0/255.alpha:1.0] forState:UIControlStateNormal];
032. [manBtn setBackgroundImage:[UIImage imageNamed:@'ic_option_mt_s@2x.png'] forState:UIControlStateSelected ];
033. [manBtn setTitleColor:[UIColor colorWithRed:255.0/255.green:255.0/255.blue:255.0/255.alpha:1.0] forState:UIControlStateSelected];
034. [manBtn setTitle:@'男' forState:UIControlStateNormal];
035. [manBtn addTarget:self  action:@selector(changeTab:) forControlEvents:UIControlEventTouchUpInside];
036. [self.view addSubview:manBtn];
037.  
038. womanBtn = [[UIButton alloc]initWithFrame:CGRectMake(62+132-240+566,30)];
039. womanBtn.tag = 203;
040. [womanBtn setBackgroundImage:[UIImage imageNamed:@'ic_option_rt_n@2x.png'] forState:UIControlStateNormal ];
041. [womanBtn setTitleColor:[UIColor colorWithRed:156.0/255.green:155.0/255.blue:155.0/255.alpha:1.0] forState:UIControlStateNormal];
042. [womanBtn setBackgroundImage:[UIImage imageNamed:@'ic_option_rt_s@2x.png'] forState:UIControlStateSelected ];
043. [womanBtn setTitleColor:[UIColor colorWithRed:255.0/255.green:255.0/255.blue:255.0/255.alpha:1.0] forState:UIControlStateSelected];
044. [womanBtn setTitle:@'女' forState:UIControlStateNormal];
045. [womanBtn addTarget:self  action:@selector(changeTab:) forControlEvents:UIControlEventTouchUpInside];
046. [self.view addSubview:womanBtn];
047.  
048. unlimitBtn.contentEdgeInsets=UIEdgeInsetsMake(-12500);
049. manBtn.contentEdgeInsets=UIEdgeInsetsMake(02500);
050. womanBtn.contentEdgeInsets=UIEdgeInsetsMake(02500);
051. [unlimitBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
052. [manBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
053. [womanBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
054.  
055. personArray = [[NSMutableArray alloc]init];
056. filteredArray =  [[NSMutableArray alloc] init];
057. sectionArray = [[NSMutableArray alloc]init];
058. userIdArray = [[NSMutableArray alloc]init];
059. jieheiArr = [[NSMutableArray alloc]init];
060. breakArr = [[NSMutableArray alloc]init];
061.  
062. NSString *path = [[NSBundle mainBundle] pathForResource:@'myinfo'ofType:@'plist'];
063. [personArray addObjectsFromArray:[NSMutableArray arrayWithContentsOfFile:path]];
064.  
065. [self initSearchBar];
066. [self initTableView];
067.  
068. }
069.  
070. -(void)initTableView
071. {
072. contectTableV = [[UITableView alloc]initWithFrame:CGRectMake(075320, self.view.frame.size.height - 75)];
073. contectTableV.dataSource = self;
074. contectTableV.delegate = self;
075. [contectTableV setBackgroundColor:[UIColor colorWithRed:231.0/255.green:231.0/255.blue:231.0/255.alpha:1.0]];
076. [contectTableV setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@'line@2x.png']]];
077. [contectTableV setAllowsMultipleSelection:YES];
078. [self.view addSubview:contectTableV];
079.  
080. searchTableV = [[UITableView alloc]initWithFrame:CGRectMake(075320, self.view.frame.size.height-75)];
081. [searchTableV setBackgroundColor:[UIColor colorWithRed:231.0/255.green:231.0/255.blue:231.0/255.alpha:1.0]];
082. [searchTableV setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@'line@2x.png']]];
083. searchTableV.delegate = self;
084. searchTableV.dataSource = self;
085. [self.view addSubview:searchTableV];
086. searchTableV.hidden = YES;
087.  
088. [self changeGroup];
089.  
090. }
091.  
092. -(void)initSearchBar
093. {
094. searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(0032040)];
095. searchbar.backgroundColor = [UIColor clearColor];
096. searchbar.tintColor = [UIColor blueColor];
097. searchbar.delegate = self;
098. for (UIView *subview in searchbar.subviews)
099. {
100. if ([subview isKindOfClass:NSClassFromString(@'UISearchBarBackground')]) {
101. [subview removeFromSuperview];
102. }
103. if ([subview isKindOfClass:[UITextField class]]) {
104. [(UITextField*)subview setBackground:[UIImage imageNamed:@'bg_search.png']];
105. [(UITextField*)subview setBackgroundColor:[UIColor clearColor]];
106. [(UITextField *)subview setBorderStyle:UITextBorderStyleNone];
107. }
108. }
109. [self.view addSubview:searchbar];
110. }
111.  
112. -(void)changeTab:(id)sender
113. {
114. if([sender tag]==201)
115. {
116. type = 2;
117. unlimitBtn.selected = YES;
118. manBtn.selected = NO;
119. womanBtn.selected = NO;
120. [unlimitBtn setFrame:CGRectMake(62456633)];
121. [manBtn setFrame:CGRectMake(62+66-1,  456630)];
122. [womanBtn setFrame:CGRectMake(62+132-2,  456630)];
123.  
124.  
125. }
126. else if([sender tag]==202)
127. {
128. type = 0;
129. unlimitBtn.selected = NO;
130. manBtn.selected = YES;
131. womanBtn.selected = NO;
132. [unlimitBtn setFrame:CGRectMake(62456630)];
133. [manBtn setFrame:CGRectMake(62+66-1,  456630)];
134. [womanBtn setFrame:CGRectMake(62+132-2,  456633)];
135.  
136. }
137. else
138. {
139. type = 1;
140. unlimitBtn.selected = NO;
141. manBtn.selected = NO;
142. womanBtn.selected = YES;
143. [unlimitBtn setFrame:CGRectMake(62456630)];
144. [manBtn setFrame:CGRectMake(62+66-1,  456630)];
145. [womanBtn setFrame:CGRectMake(62+132-2,  456633)];
146.  
147. }
148. [self getlistDataWithType:type];
149. [self changeGroup];
150.  
151.  
152. }
153. -(void)getlistDataWithType:(int)selectType
154. {
155. [personArray removeAllObjects];
156.  
157. NSString *path = [[NSBundle mainBundle] pathForResource:@'myinfo'ofType:@'plist'];
158. NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile:path];
159. if (selectType == 0)
160. {
161.  
162. for (int i = 0; i < [array count]; i++)
163. {
164. if ([[[array objectAtIndex:i]objectForKey:@'sex'] isEqualToNumber:[NSNumber numberWithInt:0]])
165. {
166. [personArray addObject:[array objectAtIndex:i]];
167. }
168. }
169. NSLog(@'manArr%@',personArray);
170. }else if (selectType == 1)
171. {
172. for (int i = 0; i < [array count]; i++)
173. {
174. if ([[[array objectAtIndex:i]objectForKey:@'sex'] isEqualToNumber:[NSNumber numberWithInt:1]])
175. {
176. [personArray addObject:[array objectAtIndex:i]];
177. }
178. }
179. NSLog(@'womanArr%@',personArray);
180. }else
181. {
182. [personArray addObjectsFromArray:array];
183. }
184.  
185. }
186.  
187. -(void)changeGroup
188. {
189. [sectionArray removeAllObjects];
190. [userIdArray removeAllObjects];
191. for (int i = 0; i < 27; i++)
192. {
193. [sectionArray addObject:[NSMutableArray array]];
194. [userIdArray addObject:[NSMutableArray array]];
195. }
196. NSString *sectionName;
197. for (NSDictionary *dict in personArray)
198. {
199. if([self searchResult:[dict objectForKey:@'nickname'] searchText:@'曾'])
200. sectionName = @'Z';
201. else if([self searchResult:[dict objectForKey:@'nickname'] searchText:@'解'])
202. sectionName = @'X';
203. else if([self searchResult:[dict objectForKey:@'nickname'] searchText:@'仇'])
204. sectionName = @'Q';
205. else if([self searchResult:[dict objectForKey:@'nickname'] searchText:@'朴'])
206. sectionName = @'P';
207. else if([self searchResult:[dict objectForKey:@'nickname'] searchText:@'查'])
208. sectionName = @'Z';
209. else if([self searchResult:[dict objectForKey:@'nickname'] searchText:@'能'])
210. sectionName = @'N';
211. else if([self searchResult:[dict objectForKey:@'nickname'] searchText:@'乐'])
212. sectionName = @'Y';
213. else if([self searchResult:[dict objectForKey:@'nickname'] searchText:@'单'])
214. sectionName = @'S';
215. else
216. sectionName = [[NSString stringWithFormat:@'%c',pinyinFirstLetter([[dict objectForKey:@'nickname'] characterAtIndex:0])] uppercaseString];
217. NSUInteger firstLetter = [ALPHA rangeOfString:[sectionName substringToIndex:1]].location;
218. if (firstLetter != NSNotFound)
219. {
220. [[sectionArray objectAtIndex:firstLetter] addObject:[dict objectForKey:@'nickname']];
221. [[userIdArray objectAtIndex:firstLetter] addObject:[dict objectForKey:@'userid']];
222. }
223. NSLog(@'changegropsectionArray:%@',sectionArray);
224. NSLog(@'changegropuserIdArray:%@',userIdArray);
225. }
226. [contectTableV reloadData];
227. [searchTableV reloadData];
228. }
229.  
230.  
231. #pragma mark -
232. #pragma mark tableViewDeleagte
233.  
234. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
235. {
236. if (tableView == contectTableV ) {
237. return 27;
238. }
239. else
240. {
241. return 1;
242. }
243. }
244.  
245.  
246. //左边的字母快速搜索
247. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
248. {
249. if(tableView == contectTableV)
250. {
251. NSMutableArray *indices = [NSMutableArray arrayWithObject:UITableViewIndexSearch];
252. for (int i = 0; i < 27; i++)
253. [indices addObject:[[ALPHA substringFromIndex:i] substringToIndex:1]];
254. return indices;
255. }
256. else
257. {
258. return nil;
259. }
260.  
261. }
262.  
263. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
264. {
265. if (title == UITableViewIndexSearch)
266. {
267. [contectTableV scrollRectToVisible:searchbar.frame animated:NO];
268. return -1;
269. }
270. return [ALPHA rangeOfString:title].location;
271.  
272. }
273.  
274. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
275. {
276. if(sectionArray.count>0)
277. {
278. if ([[sectionArray objectAtIndex:section] count] == 0)
279. {
280. return 0;
281. }
282. else
283. {
284. return 18;
285. }
286. }
287. else
288. {
289. return 0;
290. }
291.  
292. }
293.  
294. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
295.  
296. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0032018)];
297. headView.backgroundColor = [UIColor clearColor];
298.  
299. UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(05213)];
300. [lineView setBackgroundColor:[UIColor colorWithRed:42.0/255.green:42.0/255.blue:42.0/255.alpha:1.0]];
301. [headView addSubview:lineView];
302.  
303. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(55180,13)];
304. titleLabel.backgroundColor = [UIColor clearColor];
305. titleLabel.textColor = [UIColor colorWithRed:77/255.green:44/255.blue:22/255.alpha:1.0];
306. titleLabel.font = [UIFont systemFontOfSize:15.0];
307. titleLabel.text = [NSString stringWithFormat:@'%@', [[ALPHA substringFromIndex:section] substringToIndex:1]];
308. [headView addSubview:titleLabel];
309. return headView;
310.  
311. }
312.  
313. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
314. if (tableView == contectTableV)
315. {
316.  
317. return [[sectionArray objectAtIndex:section] count];
318. }
319. else
320. {
321. [filteredArray removeAllObjects];
322. NSLog(@'personarray%@',personArray);
323. for(NSDictionary *perdict in personArray)
324. {
325.  
326. NSString * name = @'';           
327. for (int i = 0; i < [[perdict objectForKey:@'nickname'] length]; i++)
328. {
329. if([name length] < 1)
330. name = [NSString stringWithFormat:@'%c',pinyinFirstLetter([[perdict objectForKey:@'nickname'] characterAtIndex:i])];
331. else
332. name = [NSString stringWithFormat:@'%@%c',name,pinyinFirstLetter([[perdict objectForKey:@'nickname'] characterAtIndex:i])];
333. }
334. if ([self searchResult:name searchText:searchbar.text])
335. [filteredArray addObject:[perdict objectForKey:@'nickname']];
336. else
337. {
338. if ([self searchResult:[perdict objectForKey:@'nickname'] searchText:searchbar.text])
339. {
340. [filteredArray addObject:[perdict objectForKey:@'nickname']];
341. }
342. }
343. }
344. return filteredArray.count;
345.  
346. }
347.  
348. }
349.  
350. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
351. {
352. static NSString *CellIdentifier = @'Cell';
353. MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
354. if (cell == nil)
355. {
356. cell = [[MyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
357. }
358. if (tableView == contectTableV)
359. {
360. if(personArray.count>0)
361. {
362. if(indexPath.row<[[sectionArray objectAtIndex:indexPath.section] count])
363. {
364. cell.nameLabel.text = [[sectionArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
365.  
366. for (NSDictionary *onedict in personArray)
367. {
368. if([cell.nameLabel.text isEqualToString:[onedict objectForKey:@'nickname']])
369.  
370. {
371. if ([[onedict objectForKey:@'sex'] isEqualToNumber:[NSNumber numberWithInt:1]])
372. {
373. [cell.headView setImage:[UIImage imageNamed:@'bg_man_01@2x.png']];
374. }
375. else
376. {
377. [cell.headView setImage:[UIImage imageNamed:@'bg_woman_01@2x.png']];
378. }
379. if ([[onedict objectForKey:@'sign'] isKindOfClass:[NSNullclass]])
380. {
381. cell.signLabel.text = @' ';
382. }
383. else
384. {
385. cell.signLabel.text = [onedict objectForKey:@'sign'];
386.  
387. }
388. }
389. }
390. }
391. }
392. }
393. else
394. {
395. if(indexPath.row<[filteredArray count])
396. {
397. cell.nameLabel.text = [filteredArray objectAtIndex:indexPath.row];
398. for (NSDictionary *onedict in personArray)
399. {
400. if([cell.nameLabel.text isEqualToString:[onedict objectForKey:@'nickname']])
401. {
402. if ([[onedict objectForKey:@'sex'] isEqualToNumber:[NSNumber numberWithInt:1]])
403. {
404.  
405. [cell.headView setImage:[UIImage imageNamed:@'bg_man_01@2x.png']];
406. }
407. else
408. {
409. [cell.headView setImage:[UIImage imageNamed:@'bg_woman_01@2x.png']];
410. }
411.  
412. if ([[onedict objectForKey:@'sign'] isKindOfClass:[NSNullclass]])
413. {
414. cell.signLabel.text = @' ';
415. }
416. else
417. {
418. cell.signLabel.text = [onedict objectForKey:@'sign'];
419.  
420. }
421.  
422. }
423.  
424. }
425. }
426. }
427. return cell;
428. }
429.  
430.  
431.  
432. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
433.  
434.  
435. NSString *userId = [[NSString alloc]init];
436. NSString *userName = [[NSString alloc]init];
437. NSLog(@'useridArr%@',userIdArray);
438. if (tableView == contectTableV)
439. {
440. userId = [[userIdArray objectAtIndex:[indexPath section]]objectAtIndex:[indexPath row]];
441. [jieheiArr addObject:userId];
442. [breakArr addObject:userId];
443. }
444. else
445. {
446. userName = [filteredArray objectAtIndex:[indexPath row]];
447. NSLog(@'username%@',userName);
448. for (int i = 0; i < [personArray count]; i++) {
449. if ([[[personArray objectAtIndex:i]objectForKey:@'nickname'] isEqualToString:userName])
450. {
451. userId = [[personArray objectAtIndex:i]objectForKey:@'userid'];
452. NSLog(@'userId%@',userId);
453. [jieheiArr addObject:userId];
454. [breakArr addObject:userId];
455. }
456.  
457. }
458. }
459. NSLog(@'jieheiarray%@ --breakarray%@',jieheiArr,breakArr);
460.  
461. }
462.  
463.  
464. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
465. {
466. NSLog(@'indexPath section%d and row%d',indexPath.section,indexPath.row);
467. NSString *userId = [[NSString alloc]init];
468. userId = [[userIdArray objectAtIndex:[indexPath section]]objectAtIndex:[indexPath row]];
469.  
470. [jieheiArr removeObject:userId];
471. [breakArr removeObject:userId];
472.  
473. NSLog(@'jieheiarray%@ --breakarray%@',jieheiArr,breakArr);
474. }
475.  
476. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
477. return 60;
478. }
479.  
480.  
481.  
482. - (void)searchBarTextDidBeginEditing:(UISearchBar *)asearchBar{
483. //    searchbar.prompt = @'输入字母、汉字或电话号码搜索';
484. }
485.  
486. - (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
487. {
488. if(searchText.length == 0)
489. {
490. [searchBar resignFirstResponder];
491. [searchbar setText:@''];
492. searchTableV.hidden = YES;
493. }
494. else
495. {
496. searchTableV.hidden = NO;
497. [searchTableV reloadData];
498. }
499.  
500. }
501. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
502. {
503. [searchBar resignFirstResponder];
504. [searchTableV reloadData];
505. searchTableV.hidden = NO;
506. }
507.  
508.  
509. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
510. {
511. [searchbar setText:@''];
512. searchbar.prompt = nil;
513. [searchbar setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
514. contectTableV.tableHeaderView = searchbar;
515. }
516.  
517.  
518. -(BOOL)searchResult:(NSString *)contactName searchText:(NSString *)searchT
519. {
520. NSComparisonResult result = [contactName compare:searchT options:NSCaseInsensitiveSearch range:NSMakeRange(0, searchT.length)];
521. if (result == NSOrderedSame)
522. return YES;
523. else
524. return NO;
525. }
526.  
527.  
528. - (void)didReceiveMemoryWarning
529. {
530. [super didReceiveMemoryWarning];
531. }
532.  
533.  
534.  
535. @end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值