views:

265

answers:

0

Hi,

This is for the main browse menu. I have a View. Inside that is a UITableView. I am populating this UITableView with my browse menu items. (icon1 - menuitem1, icon2 - menuitem2, icon3 - menuitem3 and so on)

Now the problem is: Some of the menuitems, upon clicking go to a static UI like Send Email form, FAQ screen etc., And some of the menuitems when clicked go to a screen where it invokes a API and takes couple of extra seconds than the static ones. So in this case what happens, it looks like there are 2 selections (blue highlighted) made in the main browse menu.

So I decided to suppress the highlighting bar using: [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

And I want to allow selections upon each menuitem click. So basically trying to change the background color of the cell for each menuitem selection so I have only 1 active selection highlighted at any time.

Anyone has an answer to this problem? Should I be using an image to change the background color? I tried several different methods & none is successful. Or App would crash erratically. Please provide a working example with source code.

Thanks. Hopefully I will get an answer from someone who actually got it to work;

This is the code I have used inside tableview, by creating UITableViewCell.

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *browseTableIdentifier = @"browseTableIdentifier"; tableView.backgroundColor = self.view.backgroundColor; tableView.separatorColor = [UIColor grayColor];

    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease]; NSUInteger row = [indexPath row];

    NSString *imgName = [imgArray objectAtIndex:row]; CGRect imgRect = CGRectMake(4.0, 5.0, 35, 35); UIImageView *imgView = [[UIImageView alloc] initWithFrame:imgRect]; [imgView setImage:[UIImage imageNamed:imgName]]; imgView.opaque = YES; // explicitly opaque for performance [cell.contentView addSubview:imgView]; [imgView release];

    CGRect nameRect = CGRectMake(45.0, 5.0, 200, 35); UILabel *nameView = [[UILabel alloc] initWithFrame:nameRect]; NSString *rowStr = [NSString stringWithFormat: @"%@", [listData objectAtIndex:row]]; nameView.text = rowStr; nameView.textColor = [UIColor blackColor]; nameView.font = [UIFont boldSystemFontOfSize:16]; nameView.backgroundColor = tableView.backgroundColor; [cell.contentView addSubview:nameView]; [nameView release];

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    return cell; }