UISearchController par Stéphane sudre

35
Recherche

Transcript of UISearchController par Stéphane sudre

Page 1: UISearchController par Stéphane sudre

Recherche

Page 2: UISearchController par Stéphane sudre

Recherche

Page 3: UISearchController par Stéphane sudre

Recherche

Page 4: UISearchController par Stéphane sudre

RechercheUISearchController

Page 5: UISearchController par Stéphane sudre

RecherchesearchBar 0,00 €

Page 6: UISearchController par Stéphane sudre

Recherche

searchResultsController

searchBar

Page 7: UISearchController par Stéphane sudre

searchResultsUpdater <UISearchResultsUpdating>

searchBar

searchResultsController

Recherche

Page 8: UISearchController par Stéphane sudre

<UISearchResultsUpdating>

dimsBackgroundDuringPresentation

searchBar

searchResultsController

searchResultsUpdater

Recherche

Page 9: UISearchController par Stéphane sudre

<UISearchResultsUpdating>

delegate <UISearchControllerDelegate>

searchBar

searchResultsController

searchResultsUpdater

dimsBackgroundDuringPresentation

Recherche

Page 10: UISearchController par Stéphane sudre

Exemple

0

2

4

6

8

10

12

14

16

18

20

Recherche

19:04Wanadoo E

Page 11: UISearchController par Stéphane sudre

@interface ACTableViewController () <UISearchResultsUpdating>{ ACResultsTableViewController *_resultsTableViewController; UISearchController *_searchController; NSArray *_array;}

@end

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

Page 12: UISearchController par Stéphane sudre

- (void)viewDidLoad { [super viewDidLoad]; NSMutableArray * tMutableArray=[NSMutableArray array]; for(NSUInteger tIndex=0;tIndex<100;tIndex++) [tMutableArray addObject:[@(tIndex*2) stringValue]]; _array=[tMutableArray copy]; _resultsTableViewController=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ACResultsTableViewController"]; _searchController = [[UISearchController alloc] initWithSearchResultsController:_resultsTableViewController]; _searchController.searchResultsUpdater = self; [_searchController.searchBar sizeToFit]; self.tableView.tableHeaderView = _searchController.searchBar; self.definesPresentationContext=YES;}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

Page 13: UISearchController par Stéphane sudre

_searchController = [[UISearchController alloc] initWithSearchResultsController:_resultsTableViewController]; _searchController.searchResultsUpdater = self;

10

11

12

13

Page 14: UISearchController par Stéphane sudre

_searchController = [[UISearchController alloc] initWithSearchResultsController:_resultsTableViewController]; _searchController.searchResultsUpdater = self;

10

11

12

13

Page 15: UISearchController par Stéphane sudre

[_searchController.searchBar sizeToFit];13

14

15

Page 16: UISearchController par Stéphane sudre

self.definesPresentationContext=YES;}

17

18

19

Page 17: UISearchController par Stéphane sudre

Exemple

0

2

4

6

8

10

12

14

16

18

20

Recherche

19:06Wanadoo E

Page 18: UISearchController par Stéphane sudre

Exemple Recherche

0

2

4

6

8

10

12

14

16

18

20

Recherche

22

Annuler

19:06Wanadoo E

Q W E R T Y U I O P

A S D F G H J K L

Z X C V B N M

space123 Search☺

×

Page 19: UISearchController par Stéphane sudre

Tap sur Recherche

willPresentSearchController:

update…SearchController:

didPresentSearchController:

@""

delegate

delegate

searchResultUpdater

Page 20: UISearchController par Stéphane sudre

- (void)updateSearchResultsForSearchController:(UISearchController *)inSearchController { NSString *tSearchText = inSearchController.searchBar.text; NSArray * tResultsArray=[_array objectsAtIndexes:[_array indexesOfObjectsPassingTest:^BOOL(NSString * bNumber,NSUInteger bIndex, BOOL * bOutStop) { return ([bNumber rangeOfString:tSearchText].location!=NSNotFound); }]]; _resultsTableViewController.resultsArray=tResultsArray;}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

Page 21: UISearchController par Stéphane sudre

- (void)updateSearchResultsForSearchController:(UISearchController *)inSearchController { NSString *tSearchText = inSearchController.searchBar.text;

1

2

3

Page 22: UISearchController par Stéphane sudre

Exemple Recherche

0

10

20

30

40

50

60

70

80

90

100

0

102

Annuler

19:07Wanadoo E

Q W E R T Y U I O P

A S D F G H J K L

Z X C V B N M

space123 Search☺

×

Page 23: UISearchController par Stéphane sudre

Exemple Recherche

0

10

20

30

40

50

60

70

80

90

100

0

102

Annuler

19:07Wanadoo E

  Action

Page 24: UISearchController par Stéphane sudre

Tap sur Annuler

willDismissSearchController:

update…SearchController:

didDismissSearchController:

@""

delegate

delegate

searchResultUpdater

Page 25: UISearchController par Stéphane sudre

Tap sur

update…SearchController:

update…SearchController: @""

@""

searchResultUpdater

searchResultUpdater

Page 26: UISearchController par Stéphane sudre

Exemple 2

0

2

4

6

8

10

12

14

16

18

20

Filtrage

19:08Wanadoo E

Page 27: UISearchController par Stéphane sudre

@interface ACTableViewController () <UISearchResultsUpdating>{ UISearchController *_searchController; NSArray *_originalArray; NSArray *_visibleArray;}

@end

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

Page 28: UISearchController par Stéphane sudre

- (void)viewDidLoad { [super viewDidLoad]; NSMutableArray * tMutableArray=[NSMutableArray array]; for(NSUInteger tIndex=0;tIndex<100;tIndex++) [tMutableArray addObject:[@(tIndex*2) stringValue]]; _originalArray=[tMutableArray copy]; _visibleArray=_originalArray; _searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; _searchController.searchResultsUpdater = self; _searchController.dimsBackgroundDuringPresentation=NO; [_searchController.searchBar sizeToFit]; _searchController.searchBar.placeholder=NSLocalizedString(@"Filter", @""); self.tableView.tableHeaderView = _searchController.searchBar; self.definesPresentationContext=YES;}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

Page 29: UISearchController par Stéphane sudre

_searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; _searchController.searchResultsUpdater = self;

9

10

11

12

Page 30: UISearchController par Stéphane sudre

_searchController.dimsBackgroundDuringPresentation=NO;12

13

14

Page 31: UISearchController par Stéphane sudre

Exemple 2

0

2

4

6

8

10

12

14

16

18

20

Filtrage

19:09Wanadoo E

Page 32: UISearchController par Stéphane sudre

Exemple Recherche

0

2

4

6

8

10

12

14

16

18

20

Filtrage

22

Annuler

19:09Wanadoo E

Page 33: UISearchController par Stéphane sudre

- (void)updateSearchResultsForSearchController:(UISearchController *)inSearchController { NSString *tSearchText = inSearchController.searchBar.text; if ([tSearchText length]>0) { NSArray * tResultsArray=[_originalArray objectsAtIndexes:[_originalArray indexesOfObjectsPassingTest:^BOOL(NSString * bNumber,NSUInteger bIndex, BOOL * bOutStop){ return ([bNumber rangeOfString:tSearchText].location!=NSNotFound); }]]; _visibleArray=tResultsArray; } else { _visibleArray=_originalArray; } [self.tableView reloadData];}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

Page 34: UISearchController par Stéphane sudre

Références

Exemples de codes.sudre.free.fr/Stuff/CocoaHeads/UISearchControllerSimpleCode.zip

github.com/dempseyatgithub/Sample-UISearchController

Session WWDC

A Look Inside Presentation Controllers - Session 228 - WWDC14

developer.apple.com/library/ios/samplecode/UICatalog

Page 35: UISearchController par Stéphane sudre

Q A&