I am confused about how to custom a UITableViewCell highlighted style, not only the highlighted cell background color, but also the frame of its subviews(an imageview)?
The
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
method doesn't work for me. If I only change the highlighted color of the cell, it works very well. But it doesn't work for changing the frame of cell's subviews.
Thanks for any help!
You can do it by following way
below is Sample code for it
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *strIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:strIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(278, 2, 40, 40)];
[imgv setBackgroundColor:[UIColor grayColor]];
imgv.tag = 100 + indexPath.row;
[cell.contentView addSubview:imgv];
[cell.textLabel setText:[NSString stringWithFormat:#"Cell: %d",indexPath.row]];
[cell.detailTextLabel setText:[NSString stringWithFormat:#"%03d - %03d",indexPath.section, indexPath.row]];
return cell;
}
-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell.textLabel setBackgroundColor:[UIColor orangeColor]];
//set the frame of subview on highlight
UIImageView *imgv = (UIImageView*)[cell.contentView viewWithTag:100+indexPath.row];
[imgv setBackgroundColor:[UIColor orangeColor]];
[imgv setFrame:CGRectMake(238, 2, 80, 40)];
}
-(void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell.textLabel setBackgroundColor:[UIColor clearColor]];
//now reset the frame of subview on Unhighlight
UIImageView *imgv = (UIImageView*)[cell.contentView viewWithTag:100+indexPath.row];
[imgv setBackgroundColor:[UIColor grayColor]];
[imgv setFrame:CGRectMake(278, 2, 40, 40)];
}
Best to just use the delegate protocols:
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
// and
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
Then just make the adjustments directly to your UITableViewCell via UITableViewCell *cell = [tableView cellforRowAtIndexPath:indexPath];.
Related
Hi i am beginner in Ios and in my project i have added some labels and image on table-list cell ok they have added so for everything is ok
Here my main requirement is when we tapped on table-list cell labels colors must be change and image need to be change as like below image
for this i have written some code but that's not working pleas help me
my code:-
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *cells=#"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cells];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cells];
}
strip = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 7, cell.frame.size.height)];
strip.backgroundColor = [UIColor orangeColor];
[cell.contentView addSubview:strip];
TitleLbl = [[UILabel alloc] initWithFrame:CGRectMake(65, 7, 130, 35)];
TitleLbl.text =[Right_Menu_array objectAtIndex:indexPath.row];
TitleLbl.textColor=[UIColor darkGrayColor];
TitleLbl.font = [UIFont systemFontOfSize:15];
[cell.contentView addSubview:TitleLbl];
img = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 35, 35)];
img.image = [UIImage imageNamed:[imageArr1 objectAtIndex:indexPath.row]];
[cell.contentView addSubview:img];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
TitleLbl.textColor = [UIColor redColor];
strip.backgroundColor = [UIColor redColr];
img.image = [UIImage imageNamed:#"rahul.png"];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
TitleLbl.textColor = [UIColor darkGrayColor];
strip.backgroundColor = [UIColor whiteColor];
img.image = [UIImage imageNamed:#"rahul.png"];
}
The easy way would be to create a custom UITableViewCell and then in the delegate functions of UITableView get the instance of CustomTableViewCell and set the Labels textColor.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath{
CustomTableViewCell *cell =(CustomTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.TitleLbl.textColor = [UIColor redColor];
cell.strip.backgroundColor = [UIColor redColr];
cell.img.image = [UIImage imageNamed:#"rahul.png"];
}
PS: there are many other work arounds for this...it depends on how do you want to implement the code.
Other way,
//set flag variable as
#property (strong ,nonatomic) NSIndexPath *selectedIndexPath;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.selectedIndexPath = indexPath;
[tableView reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *cells=#"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cells];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cells];
}
strip = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 7, cell.frame.size.height)];
strip.backgroundColor = [UIColor orangeColor];
TitleLbl = [[UILabel alloc] initWithFrame:CGRectMake(65, 7, 130, 35)];
TitleLbl.text =[Right_Menu_array objectAtIndex:indexPath.row];
TitleLbl.textColor=[UIColor darkGrayColor];
TitleLbl.font = [UIFont systemFontOfSize:15];
img = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 35, 35)];
img.image = [UIImage imageNamed:[imageArr1 objectAtIndex:indexPath.row]];
if(indexPath == selectedIndexPath)
{
TitleLbl.textColor = [UIColor redColor];
strip.backgroundColor = [UIColor redColr];
img.image = [UIImage imageNamed:#"rahul.png"];
}
[cell.contentView addSubview:strip];
[cell.contentView addSubview:TitleLbl];
[cell.contentView addSubview:img];
}
//This code is not tested.
I suppose you are referring to the tableview header.
You can only set tableview header view to your own custom view using the tableHeaderView property of the tableview. You can set the background color of your custom header view normally.
E.g.
self.tableView.tableHeaderView = myHeaderView;
Alternatively, if you want to modify the section header view, you can use one of the following delegate methods:
tableView:viewForHeaderInSection:
dequeueReusableHeaderFooterViewWithIdentifier:
and return your custom header view there.
From the code, I can see you hold the reference for properties of last known strip, TitleLbl and img, which will always be the components from last UITableViewCell accessed from
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Since your cell has an orange strip on left side, I would prefer creating a custom UITableViewCell to hold the references.
#interface CustomCell : UITableViewCell
#property (nonatomic,strong) UIView *strip;
#property (nonatomic,strong) UILabel *titleLbl;
#property (nonatomic,strong) UIImageView *imgView;
#end
then with a custom cell, your code can be
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *cellIdentifier = #"cellIdentifier";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
// create and add components
cell.strip = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 7, cell.frame.size.height)];
[cell.contentView addSubview:cell.strip];
cell.titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(65, 7, 130, 35)];
[cell.contentView addSubview:cell.titleLbl];
cell.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 35, 35)];
[cell.contentView addSubview:cell.imgView];
}
// modify existing components
cell.strip.backgroundColor = [UIColor orangeColor];
cell.titleLbl.text = [Right_Menu_array objectAtIndex:indexPath.row];
cell.titleLbl.textColor = [UIColor darkGrayColor];
cell.titleLbl.font = [UIFont systemFontOfSize:15];
cell.imgView.image = [UIImage imageNamed:[imageArr1 objectAtIndex:indexPath.row]];
if ([cell isSelected]) {
// remember to keep the changes for cell in it's selected state
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CustomCell *cell = (CustomCell *) [tableView cellForRowAtIndexPath:indexPath];
cell.titleLbl.textColor = [UIColor redColor];
cell.strip.backgroundColor = [UIColor redColor];
cell.imgView.image = [UIImage imageNamed:#"rahul.png"];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *) [tableView cellForRowAtIndexPath:indexPath];
cell.titleLbl.textColor = [UIColor darkGrayColor];
cell.strip.backgroundColor = [UIColor whiteColor];
cell.imgView.image = [UIImage imageNamed:#"rahul.png"];
}
also you can override the method in your custom cell
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
I have delegate method that retrieves the content for each cell like this:
-(void)getRetrievedShopContentStickerName:(NSArray *)stickerNameArray price:(NSArray *)stickerPriceArray profileBackgroundImage:(NSArray *)stickerProfileBackgroundImageArray profile:(NSArray *)stickerProfileImageArray profileMenuImage:(NSArray *)stickerProfileMenuImageArray designerName:(NSArray *)designerNameArray
{
self.stickerPriceArray = [[NSMutableArray alloc] initWithArray:stickerPriceArray];
self.stickerProfileBGImageArray = [[NSMutableArray alloc] initWithArray:stickerProfileBackgroundImageArray];
NSLog(#"sticker price: %#", self.stickerPriceArray);
NSLog(#"sticker bg: %#", self.stickerProfileBGImageArray);
[self.shopTableView reloadData];
}
This delegate methods logs out a working an array as expected. This is code I used for displaying table view content:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.stickerPriceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
AsyncImageView *backgroundImage = [[AsyncImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)]; //does cell frame get before this method?
[backgroundImage setTag:123];
[cell.contentView addSubview:backgroundImage];
UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
[priceLabel setTag:124];
[priceLabel setFont:[UIFont fontWithName:#"Helvetica-Light" size:30.0f]];
[priceLabel setTextColor:[UIColor blackColor]];
[cell.contentView addSubview:priceLabel];
}
[(AsyncImageView *)[cell.contentView viewWithTag:123] loadImageWithTypeFromURL:[NSURL URLWithString:[self.stickerProfileBGImageArray objectAtIndex:indexPath.row]] contentMode:UIViewContentModeScaleAspectFit imageNameBG:nil];
[(UILabel *)[cell.contentView viewWithTag:124] setText:[self.stickerPriceArray objectAtIndex:indexPath.row]];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
The only change I get after reloading the table view in the delegate method is the height of each tableviewcell. Why doesn't my contents show? What did I do wrong?
Thanks in advance
I accidentally set my cell's identifier in the storyboard so the if (cell == nil) was never called.
I have table view in side bar which is similar to facebook app. In my sidebar tableview i have imageview in each row. I want the imageview will be changed when i clicked the cell and it will be retain while for selecting another cell. Here is my code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
[[cell.contentView subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)];
UIView * contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
UIImageView * cellImg = [[UIImageView alloc]initWithFrame:CGRectMake(5,8,259, 60)];
[cellImg setImage:[UIImage imageNamed:[menuArr objectAtIndex:indexPath.row]]];
[contentView addSubview:cellImg];
[contentView setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:contentView];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
delegate.sideBarSelectedIndex = indexPath.row;
NSLog(#"delegate.sideBarSelectedIndex: %d",delegate.sideBarSelectedIndex);
[UIView commitAnimations];
if (self.sidebarDelegate) {
NSObject *object = [NSString stringWithFormat:#"ViewController%d", indexPath.row];
[self.sidebarDelegate sidebarViewController:self didSelectObject:object atIndexPath:indexPath];
[delegate.firstLensePageObj timerFunction:indexPath.row];
}
}
Try this in your didSelectRowAtIndexPath delegate method :-
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:#"yourImage"];
Try this in cellForRowAtIndexPath.
UIImageView *selectedImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Your Image"]];
cell.selectedBackgroundView = selectedImageView;
Need to capture the selected indexpath in didSelectRowAtIndexPath: method and need to reload the tableview in that method. In cellForRowAtIndexPath need to check the selected index with current index.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
[[cell.contentView subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)];
UIView * contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
UIImageView * cellImg = [[UIImageView alloc]initWithFrame:CGRectMake(5,8,259, 60)];
if (delegate.sideBarSelectedIndex == indexpath.row){
//Selected cell
[cellImg setImage:[UIImage imageNamed:[selectedMenuArr objectAtIndex:indexPath.row]]];
}else {
//Unselected cell
[cellImg setImage:[UIImage imageNamed:[menuArr objectAtIndex:indexPath.row]]];
}
[contentView addSubview:cellImg];
[contentView setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:contentView];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
delegate.sideBarSelectedIndex = indexPath.row;
NSLog(#"delegate.sideBarSelectedIndex: %d",delegate.sideBarSelectedIndex);
[UIView commitAnimations];
if (self.sidebarDelegate) {
NSObject *object = [NSString stringWithFormat:#"ViewController%d", indexPath.row];
[self.sidebarDelegate sidebarViewController:self didSelectObject:object atIndexPath:indexPath];
[delegate.firstLensePageObj timerFunction:indexPath.row];
}
}
I have some trouble with adding UILabel as subview to UITableViewCell. My code:
bookMarkTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 50, 480, 270)];
bookMarkTable.rowHeight = 38.0f;
bookMarkTable.backgroundColor=[UIColor colorWithRed:247/255.0 green:246/255.0 blue:242/255.0 alpha:1];
[bookMarkTable setDelegate:self];
[bookMarkTable setDataSource:self];
[bookMarkMainView addSubview:bookMarkTable];
and UITableView delegate methods:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return bookMarksArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSMutableDictionary* cellDictionary =[bookMarksArray objectAtIndex:indexPath.row];
UILabel* bookMarkTitle =[[UILabel alloc]initWithFrame:CGRectMake(50, 0, 370, 40)];
bookMarkTitle.text=[cellDictionary valueForKey:#"bm_title"];
bookMarkTitle.backgroundColor=[UIColor clearColor];
bookMarkTitle.font=[UIFont fontWithName:#"Georgia" size:20.0f];
[cell.contentView addSubview:bookMarkTitle];
return cell;
}
- (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath{
return 38.0f;
}
I add rows via this method
-(void)addBookmark{
NSMutableDictionary* infoDict=[[NSMutableDictionary alloc]init];
NSString* bookmarkTitle=[NSString stringWithFormat:#"This is :[%i]",bookMarksArray.count];
[infoDict setValue:bookmarkTitle forKey:#"bm_title"];
[bookMarksArray addObject:infoDict];
[bookMarkTable reloadData];
}
But when i invoke this method multiply times it seems that all UILabel are added more than once. Here is a result
Any help is appreciated !
What's happening is that each time you move the table, the method is called and adds a new UILabel to the cell.
You should create a subclass of UITableViewCell and add the label there.
Other option, since you are just using one label, is to use the default label of UITableViewCell.
Change
UILabel* bookMarkTitle =[[UILabel alloc]initWithFrame:CGRectMake(50, 0, 370, 40)];
bookMarkTitle.text=[cellDictionary valueForKey:#"bm_title"];
bookMarkTitle.backgroundColor=[UIColor clearColor];
bookMarkTitle.font=[UIFont fontWithName:#"Georgia" size:20.0f];
[cell.contentView addSubview:bookMarkTitle];
to
cell.textLabel.text = [cellDictionary valueForKey:#"bm_title"];
At the begin from - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath you must remove the subviews.
for(UIView* vista in cell.contentView){
[vista removeFromSuperview];
}
And that's all.
PD: Check if the removed view is the correct.
Try to change:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
with:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
I have UITableView and UISearchDisplayController. UITableViewCell is a custom cell with rowHeight = 30:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
UILabel *lbTitle;
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
lbTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.rowHeight)];
[lbTitle setTag:1];
[lbTitle setFont:[UIFont fontWithName:#"Sinhala Sangam MN" size:14]];
//[lbTitle setTextAlignment: NSTextAlignmentCenter];
[cell addSubview:lbTitle];
}
else {
lbTitle = (UILabel *)[cell viewWithTag:1];
}
}
How to apply this cell style in UISearchDisplayController. Because when search is "active" UISearchDisplayController's cell looks like basic.
Thanks
SOLVED by the help of MarkM's answer (Is there a way to customize UISearchDisplayController cell):
static NSString *normalCellReuseIdentifier = #"ANormalCell";
static NSString *searchCellReuseIdentifier = #"ASearchCell";
UITableViewCell* cell = nil;
UILabel *lbTitle;
if (tableView != self.searchDisplayController.searchResultsTableView) {
cell = [tableView dequeueReusableCellWithIdentifier:normalCellReuseIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:normalCellReuseIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
lbTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.rowHeight)];
[lbTitle setTag:1];
[lbTitle setFont:[UIFont fontWithName:#"Sinhala Sangam MN" size:14]];
//[lbTitle setTextAlignment: NSTextAlignmentCenter];
[cell addSubview:lbTitle];
}
else lbTitle = (UILabel *)[cell viewWithTag:1];
} else {
tableView.rowHeight = 30;
cell = [tableView dequeueReusableCellWithIdentifier:searchCellReuseIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:searchCellReuseIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
lbTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.rowHeight)];
[lbTitle setTag:1];
[lbTitle setFont:[UIFont fontWithName:#"Sinhala Sangam MN" size:14]];
//[lbTitle setTextAlignment: NSTextAlignmentCenter];
[cell addSubview:lbTitle];
}
else lbTitle = (UILabel *)[cell viewWithTag:1];
}
All of the same UITableView delegate methods are called with the searchResultsTableView. Please reference the following answer for a more detailed explanation.
Is there a way to customize UISearchDisplayController cell
On your instance of UISearchDisplayController (assuming it's called myUISearchDisplayController) call myUISearchDisplayController.searchResultsTableView.rowHeight = 30;
When UISearchDisplayController takes control of the table to display the results, it will call
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
To display the cell, so the only thing you have to do is detect when the displayController is calling this method:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView isMemberOfClass:[UITableView class]])
//This is the table view
else
//This is the display controller
Do the same with the rest of tghe methods of the delegate/datasource to implemente the search results cells as you want (for example, height or number of rows)
Search display controller has it's own table in which it shows the data which is searching.You can set the height by using this code-
SDC.searchResultsTableView.rowHeight = 30;//whatever you want
Where SDC is instance of UISearchDisplayController
If row height is the only thing to change. setting it with searchResultsTableView.rowHeight works only for the first time. Tapping cancel and search with new search key ignore the custom rowHeight. (iOS 6.1, xcode 4.6.1) use the below.
- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
tableView.rowHeight = 50.0;
}