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

feature request: suggestions list with custom tableview cell #7

Open
gioy opened this issue Nov 27, 2014 · 1 comment
Open

feature request: suggestions list with custom tableview cell #7

gioy opened this issue Nov 27, 2014 · 1 comment

Comments

@gioy
Copy link

gioy commented Nov 27, 2014

Hi,
first of all, thank you for your work!
When I checked out your library I was looking for something that let me customize the suggestion cells.
Being able to provide your custom cell for the suggestion list would be extremely useful, don't you think ?

@mnearents
Copy link

I know this is old, but for future people looking to use this library: It depends on your desired level of customization. There may be ways to customize it completely, but I was able to show an image view by subclassing MPGTextField and overriding cellForRowAtIndexPath

I added a value to my NSDictionary with the key @"DisplayAvatar". The MPGTextField uses a default table view cell, which already has an imageView in it, it just hides it if no image is set. So you have to set an image in cellForRowAtIndexPath

If you're looking for more customization than this, it can probably be done, but I haven't tried.

Code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MPGResultsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

NSDictionary *dataForRowAtIndexPath = [[self applyFilterWithSearchQuery:self.text] objectAtIndex:indexPath.row];
[cell setBackgroundColor:[UIColor clearColor]];
[[cell textLabel] setText:[dataForRowAtIndexPath objectForKey:@"DisplayText"]];
if ([dataForRowAtIndexPath objectForKey:@"DisplaySubText"] != nil) {
    [[cell detailTextLabel] setText:[dataForRowAtIndexPath objectForKey:@"DisplaySubText"]];
}
if ([dataForRowAtIndexPath objectForKey:@"DisplayAvatar"] != nil) {
    [[cell imageView] setImage:[dataForRowAtIndexPath objectForKey:@"DisplayAvatar"]];
}

return cell;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants