views:

412

answers:

6

Hi, 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.

A: 

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.

Robert Harvey
Hi, Robert,Thanks for responding. I'm kind of a newbie. How do I "refresh" the screen?/SD
Apparently it's not as easy as I thought: http://www.thebitsource.com/2009/04/12/a-web-developer-perspective-on-iphone-software-development/ However, it can be done, see this page for some examples: http://www.bit-101.com/blog/?p=1793
Robert Harvey
Hi, Robert,I'm a little stuck. Seems to me that what I'm seeking should be the default operation of the cells. I shouldn't have to write code to highlight the cell when it's selected, should I? I'm wondering what could be causing such a delay./Steve
Steve, these guys seem to know what they're doing: http://www.iphonedevsdk.com/forum/iphone-sdk-development/11422-how-refresh-one-region-screen.html. My relevant experience has more to do with general UI and less to do with the IPhone proper.
Robert Harvey
+1  A: 

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.

kolywater
Hi, kolywater,I'm not using a custom-drawn cell at all. I just assign the text to the cell. I really don't want to be responsible for drawing the entire cell, and I'm looking for a reason the cell delays so much in highlighting after it's touched. Seems the OS should be taking care of that!/Steve
if you remove everything from your didSelectRowAtIndex method, does the highlighting work?can you also post your didSelectRowAtIndex code?
kolywater
Hi, kolywater, I'm answering this in the post below, because quick comment will only allow me 600 characters.
Had the same issue and I am using ABTableViewCells. In the example, it was if(self.selected). Had to replace it with if(self.selected || self.highlighted). Thanks!
Sam V
A: 

Hi, kolywater,

Great idea to remove all code from didSelectRowAtIndexPath. When I do that, the highlighting happens immediately upon touch. When the code is there, there is a delay, and the highlight happens just before the new view slides into position. I want the highlight to happen first, and then have the iphone do the processing to load the new view.

Here is the code:

BeforeAfterViewController *beforeAfterViewController = [[BeforeAfterViewController alloc] initWithNibName:@"BeforeAfters" bundle:nil]; beforeAfterViewController.title = [self.listData objectAtIndex:[indexPath row]];

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
[self.navigationController pushViewController:beforeAfterViewController animated:YES]; [beforeAfterViewController release];

Here's a secondary question, if I may, which seems related. Each table row has a UITableViewCellAccessoryDetailDisclosureButton. Tapping the button takes the user to the same new view as touching the row. But picture this: the user touches row #1. Row #1 highlights and the new view slides into place. User hits the back button to see the table again. Row #1 is still highlighted. Now the user hits the accessory button on row #4. New view slides into place. But when he hits the back button to get back to the table, row #1 is still highlighted, because hitting the accessory button in row #4 did not highlight its row.

Maybe if I can force a row to highlight when that row's accessory button is tapped, I can force the highlight when the row itself is tapped?

--Steve

A: 
kolywater
A: 

Hi, kolywater,

I can't tell you how much I appreciate your input.

I changed assigning the title of the new view as you suggested.

I was setting the back button here, before the new view loads, because of this post by rames44: http://www.iphonedevsdk.com/forum/iphone-sdk-development/5833-create-custom-backbarbuttonitem.html

He says, "the metaphor is 'this is what to say when they're going back to me'".

I tried putting the backBarButtonItem assignment in the new view, but I couldn't figure out where to put it so that I could assign the title as I want.

And, sigh, I'm still not getting highlighting of the table cell until just before the new view slides into place. It's frustrating for testers who think quickly, because they press a cell, they don't get any feedback, and they press it again before the new view comes in.

--Steve

A: 

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.

Kelvin