Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass in array of TKContacts to have them preselected in the contacts list #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed TKContactPicker/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@property (nonatomic, copy) NSString *savedSearchTerm;
@property (nonatomic) NSInteger savedScopeButtonIndex;
@property (nonatomic) BOOL searchWasActive;
@property (nonatomic, retain) NSArray *preselectedContacts;

- (id)initWithGroup:(TKGroup*)group;

Expand Down
18 changes: 13 additions & 5 deletions TKContactPicker/Controllers/TKContactsMultiPickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @implementation TKContactsMultiPickerController
@synthesize savedScopeButtonIndex = _savedScopeButtonIndex;
@synthesize searchWasActive = _searchWasActive;
@synthesize searchBar = _searchBar;
@synthesize preselectedContacts;

#pragma mark -
#pragma mark Craete addressbook ref
Expand All @@ -47,7 +48,10 @@ - (void)reloadAddressBook
allPeople = ABAddressBookCopyArrayOfAllPeople(addressBooks);
peopleCount = ABAddressBookGetPersonCount(addressBooks);
}


NSArray *allPreselectedRecordIds = [self.preselectedContacts valueForKey:@"recordID"];
NSLog(@"all record ids: %@", allPreselectedRecordIds);
NSLog(@"preselected contacts: %@", self.preselectedContacts);
for (NSInteger i = 0; i < peopleCount; i++)
{
ABRecordRef contactRecord = CFArrayGetValueAtIndex(allPeople, i);
Expand Down Expand Up @@ -96,8 +100,12 @@ - (void)reloadAddressBook
}

contact.name = fullNameString;
contact.recordID = (int)ABRecordGetRecordID(contactRecord);
contact.rowSelected = NO;
contact.recordID = @((int)ABRecordGetRecordID(contactRecord));
if ([allPreselectedRecordIds containsObject:contact.recordID]) {
contact.rowSelected = YES;
} else {
contact.rowSelected = NO;
}
contact.lastName = (NSString*)abLastName;
contact.firstName = (NSString*)abName;

Expand Down Expand Up @@ -305,8 +313,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(30.0, 0.0, 28, 28)];
[button setBackgroundImage:[UIImage imageNamed:@"uncheckBox.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"checkBox.png"] forState:UIControlStateSelected];
[button setBackgroundImage:[UIImage imageNamed:@"LIST_NOT_SELECTED.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"LIST_SELECTED.png"] forState:UIControlStateSelected];
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
[button setSelected:contact.rowSelected];

Expand Down
3 changes: 2 additions & 1 deletion TKContactPicker/Controllers/TKPeoplePickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
@property (nonatomic, assign) id<TKPeoplePickerControllerDelegate> actionDelegate;
@property (nonatomic, retain) TKGroupPickerController *groupController;
@property (nonatomic, retain) TKContactsMultiPickerController *contactController;
@property (nonatomic, retain) NSArray *preselectedContacts;

- (id)initPeoplePicker;
- (id)initPeoplePicker:(NSArray*)selectedContacts;

@end
5 changes: 4 additions & 1 deletion TKContactPicker/Controllers/TKPeoplePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ @implementation TKPeoplePickerController
@synthesize actionDelegate = _actionDelegate;
@synthesize groupController = _groupController;
@synthesize contactController = _contactController;
@synthesize preselectedContacts;

#pragma mark -
#pragma mark External contacts changed callback
Expand Down Expand Up @@ -48,13 +49,15 @@ - (void)presentContactsMultiPickerController

TKContactsMultiPickerController *contactMultiController = [[TKContactsMultiPickerController alloc] initWithGroup:nil];
contactMultiController.delegate = self;
contactMultiController.preselectedContacts = self.preselectedContacts;
[self pushViewController:contactMultiController animated:NO];
self.contactController = contactMultiController;
[contactMultiController release];
}

- (id)initPeoplePicker
- (id)initPeoplePicker:(NSArray*)selectedContacts
{
self.preselectedContacts = [NSArray arrayWithArray:selectedContacts];
self.groupController = [[[TKGroupPickerController alloc] initWithNibName:NSStringFromClass([TKGroupPickerController class]) bundle:nil] autorelease];
self.groupController.delegate = self;
self = [super initWithRootViewController:self.groupController];
Expand Down