Steve Denenberg
Steve Denenberg

Reputation:

My table cells don't highlight immediately when touched

In my app, I have a table view that has about eight cells. There is a navigation bar at the top. When a user touches a cell, nothing happens for about 1/2 second. Then the touched cell highlights blue and immediately the new view slides into position.

The problem is that there is no feedback to the user about which cell he touched until just before the new view slides into position.

For example, when I explore the tables in the iPhone's Settings application, when you touch a cell, the cell immediately turns blue, and then there is a 1/2 second delay, and then you see the new view.

How do I get my table's feedback of highlighting the cells to happen immediately? I am using tableView didSelectRowAtIndexPath:, and each cell has an accessory button.

Thanks for any insight.

Upvotes: 0

Views: 1066

Answers (4)

Kelvin
Kelvin

Reputation: 1182

You may put these 2 lines of code at the beginning of the didSelectRowAtIndexPath method:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setSelected:YES animated:YES];

it should first highlight the cell before processing other program logic.

Upvotes: 0

kolywater
kolywater

Reputation: 61

a few things:

it's probably best to have a property in beforeViewController so it can set its own title on load (instead of setting it from the parent class).

second, why are you setting the back button for the current class? youre also leaking that (you alloc the UIBarButtonItem but dont release it).


NewViewController *newViewController = [[[NewViewController alloc]
initWithNibName:@"New" bundle:nil] autorelease];
newViewController.name = [self.listData objectAtIndex:indexPath.row];
[self.navigationController pushViewController:beforeAfterViewController animated:YES]; 

then in NewViewController, you have


- (void) viewDidLoad{
    self.title = self.name;
}


re: your secondary question: if you pop the child controller using [self.navigationController popViewControllerAnimated:YES], the parent view should auto-deselect the row that was previously selected. it shoulnt stay selected unless you are forcing it to stay that way.

you don't need to do anything like [self.tableView deselectRowAtIndexPath:] unless you are not pushing child views (and doing something like checkmarking a cell that the user tapped).

Upvotes: 0

kolywater
kolywater

Reputation: 61

are you using a custom-drawn cell (with a drawRect override) or something like that?

if you have a custom drawRect method, you'll need to do something like this (based off the code for tweetie, found here):


//default colors for cell
UIColor *backgroundColor = [UIColor whiteColor];
UIColor *textColor = [UIColor blackColor];

//on highlight, swap colors
if(self.highlighted){
    backgroundColor = [UIColor clearColor];
    textColor = [UIColor whiteColor];
}

that should give you the default behavior.

Upvotes: 1

Robert Harvey
Robert Harvey

Reputation: 180878

It sounds like the screen is refreshing after the new slide has been processed. You need to refresh the screen before rendering the new slide view.

Upvotes: 0

Related Questions