Reputation: 79
I am using storyboard and custom cells. I am trying to search. It works all fine and loads the custom cell when the tableviewcontroller loads , as soon as i enter a search character, the cell returned is UITableViewCellStyleDefault and i can only set the label, i am not sure why it is not picking the custom cell. Can someone please help.
sorry its a repeat of this but i could not figure out how that worked.
i am using this code.
static NSString *CellIdentifier = @"memberCell";
MemberCell *cell = (MemberCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *item = self.searchList[indexPath.row];
if (cell == nil) {
cell = [[MemberCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.memberFullName.text = [item[@"full_name"] uppercaseString] ;
cell.memberPosition.text = [item[@"title"] length] < 1 ? [NSString stringWithFormat:@"%@", item[@"districts"]] : [NSString stringWithFormat:@"%@, %@", item[@"title"], item[@"districts"]];
cell.memberRoom.text = [NSString stringWithFormat:@"Rm %@", item[@"room_number"] ];
[cell.memberImage setImageWithURL:[NSURL URLWithString:item[@"image_thumb"]]
placeholderImage:[UIImage imageNamed:@"placeholder"]];
Deepak
Upvotes: 0
Views: 1528
Reputation: 7758
You said "I am trying to search" - do you mean that you added a UISearchDisplayController
and you are trying to get your custom cell to appear in that results table view? If so, you have 2 options:
In the tableView:cellForRowAtIndexPath:
method you need to dequeue the custom cell from your main table view and NOT the search results table view. When you define a cell in tableview that is in a storyboard, the storyboard only registers it with that tableview, so it isn't dequeueable from any other tableview (I confirmed this with the apple engineer responsible for storyboards at WWDC '13). So, the code would look like this instead:
MemberCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Move your custom cell definition into a standalone xib file (create an empty XIB, drag a UITableViewCell from the objects list and configure it as desired). Define a custom cell class and configure that as the cell class in the xib, and then you can manually register that cell type with both table views using registerNib:forCellReuseIdentifier:
Upvotes: 1