MLPAutoCompleteTextField icon indicating copy to clipboard operation
MLPAutoCompleteTextField copied to clipboard

Using a custom xib file for the TableViewCell

Open boazin opened this issue 9 years ago • 4 comments

Is it supported? I'm having trouble with it...

boazin avatar Mar 15 '15 19:03 boazin

hello, yes, using custom xib files for the tableViewCell(s) is possibile. Even if the demo won't build, you should take a look at the following MLPAutoCompleteTextField's methods:

  • (void)registerAutoCompleteCellClass:(Class)cellClass forCellReuseIdentifier:(NSString *)reuseIdentifier
  • (void)registerAutoCompleteCellNib:(UINib *)nib forCellReuseIdentifier:(NSString *)reuseIdentifier

in the MLPAutoCompleteTextField/MLPAutoCompleteTextField.m file

Also, take a look at the DEMOViewController and DEMOCustomAutoCompleteCell classes.

gioy avatar Mar 16 '15 12:03 gioy

This one I did find, and here's exactly where I got complicated. Usually when I have a UITableView the cellForRowAtIndexPath has something like:

MyCell *cell = (SnackCell *)[tableView dequeueReusableCellWithIdentifier:@"myCellID"];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"myCellID" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

How do I incorporate this concept into registerAutoCompleteCellNib (it constantly kept crashing)

Thanks for the help - love the package

boazin avatar Mar 16 '15 12:03 boazin

I'll elaborate. I have a text and an image. The image is downloaded async via SDWebImage It's size is unknown - and I want to "resize" it after download. Couldn't do it so far with the default UIImageView. A possible solution is a custom cell (As discussed in https://github.com/rs/SDWebImage/issues/30) But I got in trouble when trying to add my xib (with it's "attached" class)

A point to the direction (or a demo with xib) will be appreciated

boazin avatar Mar 16 '15 16:03 boazin

If you need to use a custom UITableViewCell with the MLPAutoCompleteTextField, you just need to define which Cell Class and Cell xib you want to use. In your ViewController (where you're using the MLPAutoCompleteTextField instance), usually (but not necessarily) inside the - (void)viewDidLoad method, you just need to call the methods previously mentioned: (void)registerAutoCompleteCellClass:(Class)cellClass forCellReuseIdentifier:(NSString *)reuseIdentifier and (void)registerAutoCompleteCellNib:(UINib *)nib forCellReuseIdentifier:(NSString *)reuseIdentifier

Example:

for example's sake, let's suppose that:

  • your custom UITableViewCell sub class is called MyCustomCell
  • your Cell view is called MyCustomCell.xib
  • your view controller's MLPAutoCompleteTextField property is defined as:
@property (weak, nonatomic) IBOutlet MLPAutoCompleteTextField *searchField;

in your view controller's viewDidLoad method you'll have:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [_searchField registerClass:[MyCustomCell class]
           forCellReuseIdentifier:@"MyCustomCell"];

    [_searchField registerAutoCompleteCellNib:[UINib nibWithNibName:@"MyCustomCell" bundle:nil]
           forCellReuseIdentifier:@"MyCustomCell"];
}

gioy avatar Mar 20 '15 08:03 gioy