forked from thermogl/TITokenField
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTITokenTableViewController.m
699 lines (516 loc) · 22.8 KB
/
TITokenTableViewController.m
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
//
// TokenTableViewController.m
// TokenFieldExample
//
// Created by jac on 9/5/12.
//
//
#import "TITokenTableViewController.h"
#pragma mark - TITokenTableView
@implementation TITokenTableView
@dynamic delegate;
- (void)reloadData
{
self.reloading = YES;
[super reloadData];
self.reloading = NO;
if ([self.delegate respondsToSelector:@selector(tableViewDidFinishReloading:)])
{
[self.delegate tableViewDidFinishReloading:self];
}
}
@end
#pragma mark - TITokenTableViewController
@interface TITokenTableViewController ()
@property (nonatomic, strong) NSMutableDictionary *tokenFields;
@end
@implementation TITokenTableViewController
@synthesize showAlreadyTokenized, sourceArray, resultsTable = resultsTable;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
_tokenFieldsEditable = YES;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView =
[[TITokenTableView alloc] initWithFrame:self.view.bounds
style:UITableViewStylePlain];
self.tableView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view insertSubview:self.tableView atIndex:0];
showAlreadyTokenized = NO;
resultsArray = [[NSMutableArray alloc] init];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
UITableViewController * tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[tableViewController.tableView setDelegate:self];
[tableViewController.tableView setDataSource:self];
[tableViewController setContentSizeForViewInPopover:CGSizeMake(400, 400)];
resultsTable = tableViewController.tableView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
}
else
{
resultsTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0 + 1, self.view.bounds.size.width, self.view.bounds.size.height)];
resultsTable.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[resultsTable setSeparatorColor:[UIColor colorWithWhite:0.85 alpha:1]];
[resultsTable setBackgroundColor:[UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1]];
[resultsTable setDelegate:self];
[resultsTable setDataSource:self];
[resultsTable setHidden:YES];
[self.view addSubview:resultsTable];
[self.view bringSubviewToFront:resultsTable];
popoverController = nil;
}
NSNotificationCenter *notifCenter = [NSNotificationCenter defaultCenter];
[notifCenter addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[notifCenter addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (_searchResultIsVisible)
{
CGRect resultsFrame = resultsTable.frame;
resultsFrame.size.height = self.view.frame.size.height - _keyboardHeight - resultsFrame.origin.y;
resultsTable.frame = resultsFrame;
}
}
#pragma mark - Token field for prompt
- (NSMutableDictionary *)tokenFields
{
if (!_tokenFields)
{
_tokenFields =
[NSMutableDictionary dictionaryWithCapacity:self.tokenDataSource.numberOfTokenRows];
}
return _tokenFields;
}
- (TITokenField *)tokenFieldForPrompt:(NSString *)prompt
{
// Return existing token field if any
TITokenField *tokenField = self.tokenFields[prompt];
if (tokenField)
return tokenField;
// Else set it up and add it to self.tokenFields
tokenField = [[TITokenField alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 42)];
// tokenField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// Hook it up to the dictionary immediately so that in the event this
// method calls for the same token field again we won't recreate another one
[self.tokenFields setObject:tokenField forKey:prompt];
// Hook up the target-action pair
[tokenField addTarget:self action:@selector(tokenFieldDidBeginEditing:) forControlEvents:UIControlEventEditingDidBegin];
[tokenField addTarget:self action:@selector(tokenFieldDidEndEditing:) forControlEvents:UIControlEventEditingDidEnd];
[tokenField addTarget:self action:@selector(tokenFieldTextDidChange:) forControlEvents:UIControlEventEditingChanged];
[tokenField addTarget:self action:@selector(tokenFieldFrameWillChange:) forControlEvents:TITokenFieldControlEventFrameWillChange];
[tokenField addTarget:self action:@selector(tokenFieldFrameDidChange:) forControlEvents:TITokenFieldControlEventFrameDidChange];
[tokenField addTarget:self action:@selector(tokenFieldChangedEditing:) forControlEvents:UIControlEventEditingDidBegin];
[tokenField addTarget:self action:@selector(tokenFieldChangedEditing:) forControlEvents:UIControlEventEditingDidEnd];
//
if (self.tokenizingCharacters)
[tokenField setTokenizingCharacters:self.tokenizingCharacters];
if (self.tokenFieldFont)
[tokenField setFont:self.tokenFieldFont];
[tokenField setEditable:self.tokenFieldsEditable];
// If tokens are not editable, make sure they are always shown in
// token form
if (!self.tokenFieldsEditable)
{
[tokenField setRemovesTokensOnEndEditing:NO];
}
[tokenField setDelegate:self];
[tokenField setPromptText:prompt];
UIView *accessoryView = [self.tokenDataSource accessoryViewForField:tokenField];
if (accessoryView) {
[tokenField setRightView:accessoryView];
// Hook up the didTapOnAccesoryView action
if ([accessoryView respondsToSelector:@selector(addTarget:action:forControlEvents:)])
{
[(id) accessoryView addTarget:tokenField
action:@selector(didTapOnAccessoryView:)
forControlEvents:UIControlEventTouchUpInside];
}
if (!self.tokenFieldsEditable)
[tokenField setRightViewMode:UITextFieldViewModeAlways];
}
if ([self.delegate respondsToSelector:
@selector(tokenTableViewController:didFinishSettingUpTokenField:)])
{
[self.delegate tokenTableViewController:self
didFinishSettingUpTokenField:tokenField];
}
return tokenField;
}
#pragma mark - Token field properties
- (void)setTokenizingCharacters:(NSCharacterSet *)tokenizingCharacters
{
if (_tokenizingCharacters != tokenizingCharacters)
{
_tokenizingCharacters = tokenizingCharacters;
// Update existing token fields if any
for (TITokenField *tokenField in self.tokenFields)
{
[tokenField setTokenizingCharacters:tokenizingCharacters];
}
}
}
- (void)setTokenFieldFont:(UIFont *)tokenFieldFont
{
if (_tokenFieldFont != tokenFieldFont)
{
_tokenFieldFont = tokenFieldFont;
// Update existing token fields if any
for (TITokenField *tokenField in self.tokenFields)
{
[tokenField setFont:tokenFieldFont];
}
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.tableView) {
NSUInteger rows = self.tokenDataSource.numberOfTokenRows;
// another cell that is not a TIToken (e.g. subject, body)
if ([self.tokenDataSource respondsToSelector:@selector(tokenTableView:numberOfRowsInSection:)]) {
rows += [self.tokenDataSource tokenTableView:self numberOfRowsInSection:section];
}
return rows;
}
if (tableView == resultsTable) {
return resultsArray.count;
}
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
if (indexPath.row < self.tokenDataSource.numberOfTokenRows)
{
NSString *promptAtRow =
[self.tokenDataSource tokenFieldPromptAtRow:(NSUInteger)indexPath.row];
TITokenField *tokenField = [self tokenFieldForPrompt:promptAtRow];
CGFloat height = tokenField.frame.size.height;
return height;
}
else
{
// a row that is not a token field: delegate
if ([self.tokenDataSource respondsToSelector:@selector(tokenTableView:heightForRowAtIndexPath:)]) {
NSIndexPath * idx = [NSIndexPath indexPathForRow:indexPath.row - self.tokenDataSource.numberOfTokenRows inSection:indexPath.section];
return [self.tokenDataSource tokenTableView: self heightForRowAtIndexPath:idx];
}
}
}
if (tableView == resultsTable) {
//todo
// if (tokenField && [tokenField.delegate respondsToSelector:@selector(tokenField:resultsTableView:heightForRowAtIndexPath:)]){
// return [tokenField.delegate tokenField:tokenField resultsTableView:tableView heightForRowAtIndexPath:indexPath];
// }
return 44;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
// DISPLAYING THE TOKEN TABLE
if (tableView == self.tableView) {
static NSString *CellIdentifier = @"Cell";
// any TokenCell
if (indexPath.row < self.tokenDataSource.numberOfTokenRows)
{
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSString *promptAtRow =
[self.tokenDataSource tokenFieldPromptAtRow:(NSUInteger)indexPath.row];
TITokenField *tokenField = [self tokenFieldForPrompt:promptAtRow];
BOOL shouldRemakeTokenFieldFirstResponder =
(tokenField == self.currentSelectedTokenField);
// This resigns first responder for the tokenField if it is
// already the token field, leaving nothing as first responder
[cell.contentView addSubview:tokenField];
// This fixes the bug where we could end up with no first
// responder when the table is somehow reloaded or remade
if (shouldRemakeTokenFieldFirstResponder)
{
[tokenField becomeFirstResponder];
}
}
}
else
{
// another cell that is not a TIToken (e.g. subject, body)
if ([self.tokenDataSource respondsToSelector:@selector(tokenTableView:cellForRowAtIndexPath:)]) {
NSIndexPath *idx = [NSIndexPath indexPathForRow:indexPath.row - self.tokenDataSource.numberOfTokenRows inSection:indexPath.section];
cell = [self.tokenDataSource tokenTableView:self cellForRowAtIndexPath:idx];
}
}
}
// DISPLAYING THE SEARCH RESULT
if (tableView == resultsTable) {
id representedObject = [resultsArray objectAtIndex:(NSUInteger) indexPath.row];
//todo, shall the delegate be able to give a result cell ?
if ([self.currentSelectedTokenField.delegate respondsToSelector:@selector(tokenField:resultsTableView:cellForRepresentedObject:)])
{
return [self.currentSelectedTokenField.delegate tokenField:self.currentSelectedTokenField
resultsTableView:tableView
cellForRepresentedObject:representedObject];
}
static NSString *CellIdentifier = @"ResultsCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *subtitle =
[self searchResultSubtitleForRepresentedObject:representedObject
inTokenField:self.currentSelectedTokenField];
if (!cell) {
if (subtitle) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
} else {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
}
cell.detailTextLabel.text = subtitle;
[cell.textLabel setText:[self searchResultStringForRepresentedObject:representedObject]];
}
// Configure the cell...
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
if ([self.delegate respondsToSelector:@selector(tokenTableViewController:didSelectRowAtIndex:)]) {
NSInteger row = indexPath.row - self.tokenDataSource.numberOfTokenRows;
[self.delegate tokenTableViewController:self didSelectRowAtIndex:row];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
if (tableView == resultsTable) {
TITokenField *tokenField = self.currentSelectedTokenField;
if (tokenField) {
id representedObject = [resultsArray objectAtIndex:(NSUInteger) indexPath.row];
TIToken *token = [[TIToken alloc] initWithTitle:[self displayStringForRepresentedObject:representedObject] representedObject:representedObject];
// Use the token field's tint color if any
if (tokenField.tintColor)
token.tintColor = tokenField.tintColor;
[tokenField addToken:token];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self setSearchResultsVisible:NO forTokenField:tokenField];
}
}
}
#pragma mark - TextField Methods
- (void)tokenFieldDidBeginEditing:(TITokenField *)field {
if([self.delegate respondsToSelector:@selector(tokenTableViewController:didSelectTokenField:)]) {
[self.delegate tokenTableViewController:self didSelectTokenField:field];
}
self.currentSelectedTokenField = field;
UIView * cell = field.superview;
while (cell && ![cell isKindOfClass:[UITableViewCell class]]) {
cell = cell.superview;
}
[resultsArray removeAllObjects];
[resultsTable reloadData];
}
- (void)tokenFieldDidEndEditing:(TITokenField *)field {
[self setSearchResultsVisible:NO forTokenField:field];
self.currentSelectedTokenField = nil;
}
- (void)tokenFieldTextDidChange:(TITokenField *)field {
[self resultsForSearchString:[field.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}
- (void)tokenFieldFrameWillChange:(TITokenField *)field {
//NSLog(@"%s %@", __PRETTY_FUNCTION__, field);
if ([self.delegate respondsToSelector:@selector(tokenTableViewController:tokenFieldFrameWillChange:)]) {
[self.delegate tokenTableViewController:self tokenFieldFrameWillChange:field];
}
// this resizes the table cells animated
[self updateContentSize];
}
- (void)tokenFieldFrameDidChange:(TITokenField *)field {
//NSLog(@"%s %@", __PRETTY_FUNCTION__, field);
//[self.tableView endUpdates];
// [self updateContentSize];
if ([self.delegate respondsToSelector:@selector(tokenTableViewController:tokenFieldFrameDidChange:)]) {
[self.delegate tokenTableViewController:self tokenFieldFrameDidChange:field];
}
}
#pragma mark - Results Methods
- (NSString *)displayStringForRepresentedObject:(id)object {
TITokenField *tokenField = self.currentSelectedTokenField;
if ([tokenField.delegate respondsToSelector:@selector(tokenField:displayStringForRepresentedObject:)]){
return [tokenField.delegate tokenField:tokenField displayStringForRepresentedObject:object];
}
if ([object isKindOfClass:[NSString class]]){
return (NSString *)object;
}
return [NSString stringWithFormat:@"%@", object];
}
- (NSString *)searchResultStringForRepresentedObject:(id)object {
TITokenField *tokenField = self.currentSelectedTokenField;
if ([tokenField.delegate respondsToSelector:@selector(tokenField:searchResultStringForRepresentedObject:)]){
return [tokenField.delegate tokenField:tokenField searchResultStringForRepresentedObject:object];
}
return [self displayStringForRepresentedObject:object];
}
- (NSString *)searchResultSubtitleForRepresentedObject:(id)object inTokenField:(TITokenField *)tokenField {
if ([tokenField.delegate respondsToSelector:@selector(tokenField:searchResultSubtitleForRepresentedObject:)]){
return [tokenField.delegate tokenField:tokenField searchResultSubtitleForRepresentedObject:object];
}
return nil;
}
- (void)setSearchResultsVisible:(BOOL)visible forTokenField:(TITokenField *)tokenField {
// dont set it twice
if (_searchResultIsVisible == visible) {
return;
}
_searchResultIsVisible = visible;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
if (visible) [self presentpopoverAtTokenFieldCaretAnimated:YES inTokenField:tokenField];
else [popoverController dismissPopoverAnimated:YES];
}
else
{
NSInteger scrollToRow = 0;
if (visible) {
// showing the search result table: scroll the current cell to top
NSInteger count = self.tokenDataSource.numberOfTokenRows;
for (NSUInteger row = 0; row < count; row++) {
NSString *rowPrompt = [self.tokenDataSource tokenFieldPromptAtRow:row];
if ([rowPrompt isEqualToString:tokenField.promptText]) {
scrollToRow = row;
break;
}
}
_contentOffsetBeforeResultTable = self.tableView.contentOffset;
// find the containing cell to bring it to front
UIView *cell = tokenField.superview;
while (cell && ![cell isKindOfClass:[UITableViewCell class]]) {
cell = cell.superview;
}
// if (cell) {
// [self.tableView bringSubviewToFront:cell];
// }
NSIndexPath * idx = [NSIndexPath indexPathForRow:scrollToRow inSection:0];
CGRect rowRect = [self.tableView rectForRowAtIndexPath:idx];
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {}
else {
rowRect.origin.y -= 20;
}
[UIView animateWithDuration:0.3 animations:^{
[self.tableView setContentOffset:rowRect.origin animated:NO];
// size is from the token till the beginning of the keyboard
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
resultsTable.frame = CGRectMake(0, tokenField.frame.size.height + 1, self.view.bounds.size.width, self.view.bounds.size.height - _keyboardHeight - tokenField.frame.size.height);
}
else {
resultsTable.frame = CGRectMake(0, tokenField.frame.size.height + 1+20, self.view.bounds.size.width, self.view.bounds.size.height - _keyboardHeight - tokenField.frame.size.height);
}
} completion:^(BOOL finished) {
// Make it visible only if the the result table is still
// meant to be visible. For example the user might have
// continued typing more text that does not match anything
// and thus would have already hidden the table during the
// animation
if (_searchResultIsVisible)
{
[self.view bringSubviewToFront:resultsTable];
[resultsTable setHidden:NO];
}
}];
}
else {
// hiding result table, scroll back to where we were,
[self.tableView setContentOffset:_contentOffsetBeforeResultTable];
[resultsTable setHidden:!visible];
}
[tokenField setResultsModeEnabled:visible];
self.tableView.scrollEnabled = !visible;
}
}
- (void)resultsForSearchString:(NSString *)searchString {
TITokenField *tokenField = self.currentSelectedTokenField;
// The brute force searching method.
// Takes the input string and compares it against everything in the source array.
// If the source is massive, this could take some time.
// You could always subclass and override this if needed or do it on a background thread.
// GCD would be great for that.
[resultsArray removeAllObjects];
[resultsTable reloadData];
[sourceArray enumerateObjectsUsingBlock:^(id sourceObject, NSUInteger idx, BOOL *stop){
NSString * query = [self searchResultStringForRepresentedObject:sourceObject];
NSString * querySubtitle = [self searchResultSubtitleForRepresentedObject:sourceObject inTokenField:tokenField];
BOOL hasQueryAndMatchesSearch =
(query != nil) &&
[query rangeOfString:searchString
options:NSCaseInsensitiveSearch].location != NSNotFound;
BOOL hasQuerySubtitleAndMatchesSearch =
(querySubtitle != nil) &&
[querySubtitle rangeOfString:searchString
options:NSCaseInsensitiveSearch].location != NSNotFound;
if (hasQueryAndMatchesSearch || hasQuerySubtitleAndMatchesSearch)
{
__block BOOL shouldAdd = ![resultsArray containsObject:sourceObject];
if (shouldAdd && !showAlreadyTokenized){
[tokenField.tokens enumerateObjectsUsingBlock:^(TIToken * token, NSUInteger idx, BOOL *secondStop){
if ([token.representedObject isEqual:sourceObject]){
shouldAdd = NO;
*secondStop = YES;
}
}];
}
if (shouldAdd) [resultsArray addObject:sourceObject];
}
}];
[resultsArray sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [[self searchResultStringForRepresentedObject:obj1 ] localizedCaseInsensitiveCompare:[self searchResultStringForRepresentedObject:obj2]];
}];
[resultsTable reloadData];
[self setSearchResultsVisible:(resultsArray.count > 0) forTokenField:tokenField];
}
- (void)presentpopoverAtTokenFieldCaretAnimated:(BOOL)animated inTokenField:(TITokenField *)tokenField {
UITextPosition * position = [tokenField positionFromPosition:tokenField.beginningOfDocument offset:2];
[popoverController presentPopoverFromRect:[tokenField caretRectForPosition:position] inView:tokenField
permittedArrowDirections:UIPopoverArrowDirectionUp animated:animated];
}
- (void)tokenFieldChangedEditing:(TITokenField *)tokenField {
// There's some kind of annoying bug where UITextFieldViewModeWhile/UnlessEditing doesn't do anything.
[tokenField setRightViewMode:(tokenField.editing ? UITextFieldViewModeAlways : UITextFieldViewModeNever)];
}
-(void) updateContentSize {
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
- (void)keyboardWillShow:(NSNotification *)notification {
CGRect keyboardRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
_keyboardHeight = keyboardRect.size.height > keyboardRect.size.width ? keyboardRect.size.width : keyboardRect.size.height;
}
- (void)keyboardWillHide:(NSNotification *)notification {
_keyboardHeight = 0;
}
- (void)dealloc {
[self setDelegate:nil];
}
@end