How do you have a cell highlight momentarily and fade out when selected?

I've noticed that in some apps, when the user selects a table view cell, it will momentarily highlight, but the highlight will immediately fade out (i.e. you can tell that the cell has been highlighted, but the highlight doesn't stay -there is just a checkmark).
When I select a cell, I want the selected cell to stay selected, but have the highlight fade out immediately. I can't see any options to achieve this effect. I've tried using the setHighlight edmethod to set the cell to be unhighlighted in the didSelectRowAtIndexPath method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewCell* tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryType = UITableViewCellAccessoryCheckmark;
[tableViewCell setHighlighted:NO animated:YES];
However, this does not appear to work. I don't know if this is because I've done something wrong with trying to implement this code, or if the approach I'm attempting is not how you're supposed to go about it. If anybody has any ideas I'd be grateful.

m_userName wrote:
When I select a cell, I want the selected cell to stay selected, but have the highlight fade out immediately. I can't see any options to achieve this effect. I've tried using the setHighlight edmethod to set the cell to be unhighlighted in the didSelectRowAtIndexPath method:
The Selected State and the Highlighted State are actually independent. I.e. a cell can be selected but not highlighted and vice versa. This can be confusing because, for a standard cell the appearance of the Highlighted State tracks the Selected State style (except the Highlighted State doesn't change the label text to white). But if you subclass a cell you can make the two states appear quite different.
So the solution is to turn off the Selected State of the cell. This doesn't change which index path is selected. The table view keeps track of that, so turning off the Selected State of the cell only affects its appearance. However, whenever a selected index path is scrolled out of view and then back, the cell that's placed at that index path must be manually reset to it's Non-Selected state before it's displayed. This is because whenever a cell for the selected index path is obtained from tableView:cellForRowAtIndexPath:, the system will set that cell to the Selected State.
// MyTableViewController.m
#import "MyTableViewController.h"
@implementation MyTableViewController
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 24;
- (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.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
// set selection style to None here to prevent a flash when indexPath is selected
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
- (void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.selected = NO;
BOOL isSelectedPath =
[indexPath compare:[tableView indexPathForSelectedRow]] == NSOrderedSame;
cell.accessoryType = isSelectedPath ?
UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
// reset selection style here, after the cell has been set to the Non-Selected state
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryType = UITableViewCellAccessoryNone;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryType = UITableViewCellAccessoryCheckmark;
[tableViewCell setSelected:NO animated:YES]; // <-- setSelected instead of setHighlighted
@end
- Ray

Similar Messages

  • How do you have 2 Safari windows open and show both pages simultaneously on the monitor

    How do you keep open 2 Safari windows and show both pages on monitor?

    While in Safari with your first window open go to the File menu and select New Window. That will open the second window on which you can navigate to your second web page. Resize both windows to fit on your display.

  • How do you change the pink highlight for the present day in calendar when in week view

    How do you change the pink highlight for the present day in calendar when in week view - OSX Maverick

    the current day was light blue in ical in 10.6 but with plenty of contrast, but I recently made the bigger leap all the way to calendar in 10.9. the choice of color is terrible for reasons such as Spile1962 puts below, but also not having any way to tweak it is terrible. I'm on a bran d new imac and can barely see a difference and frankly, while I appreciate the subtlety, I still forget to look for the darker bar across the top of the current week and day. we should be able to adjust weekend and current day bg colors.
    I went into the app's package contents in hopes that they were using a tiff/png file that I could tweak on my own but couldn't find anything for them. all the icons are there, as are the bg sets for all the little pop-ups and things, but I couldn't even find a reference to a hex color in the plist file.
    send apple feedback. I just did myself, except that Calendar hasn't made the list (yet?), only iCal up to version 4.x, and Messages is still only iChat for feedback, and some others are old as well. apparently after steve died, apple's attention to these details just died with him. it's been that long since those other apps should have been relevant on their site.

  • How do you have multiple apple id's with one itunes

    how do you have multiple apple id's with one itunes

    I have multiple IDs and use the single computer sharing itunes. By 'sharing' I mean we open the pc, open itunes and log in with our individual ID as required.
    While Im logged in I plug in  my device. I transfer my purchases from my device as per the file menu (not the check for auto downloads). I move them as required to whichever playlist I like.
    Then when my son wants to use itunes or update his device, he logs in, plugs in his device, transfers purchases from his device, puts whatever music he wants into his playlist and/or drags direct to the device regardless of who purchased it and then syncs.
    Im not sure how it works associating the pc with only one ID or all that other business- I know I don't fiddle with any of that.

  • When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???

    When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???  All of the songs that were put on there from a CD will sync, but the songs that were purchased.. "cannot be found"   How can we merge them?? or how can we share all songs.. purchased or not!

    When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???  All of the songs that were put on there from a CD will sync, but the songs that were purchased.. "cannot be found"   How can we merge them?? or how can we share all songs.. purchased or not!

  • How do you get your album's songs to stay together when you put them on your ipod/iphone, when some songs have a ft. artist?

    How do you get your album's songs to stay together when you put them on your ipod/iphone, when some songs have a ft. artist?
    Even when I try to change the featured artist in my I tunes, it won't stay with my other songs, and I want to be able to listen to my album in the order of the songs that the album has it.

    The iTunes/iPod software isn't set up to let you sync songs from more than one libray, but if you manually manage the iPod you can add tracks from multiple computers without removing the existing content. Personnaly I think syncing with a library is a much better way to manage your iPod, so I'd suggest you just copy the stuff you bought at work onto a memory stick, then take it home and import it into your iTunes library there.
    tt2

  • HT1229 How do you transfer photos to external backup and keep the photos in events with event name or with description name. Each time I have tried to transfer them they only transfer with a jpg number so you don't know what photos are what.

    How do you transfer photos to external backup and keep the photos in events with event name or with description name. Each time I have tried to transfer them they only transfer with a jpg number so you don't know what photos are what. When you have several thousand photos it is difficult to determined what is what.
    Why does iPhoto have the ability to put photos in events and to give them descriptions if it doesn't transfer this info with the photo. I want to back my photos up to an external drive.

    The simplest way to achieve what you want is to back up the iPhoto Library. That will get everything.
    You sem to be exporting from iPhoto to the Finder. The Finder does not have the same organisation capabilities as iPhoto. If you're going to do that you need to understand some of the differences between the two.
    Event Name will become  Folder Name.
    'Description Name' I guess is the Title you give the Photo
    Jpeg Number is the File Name assigned by your camera.
    So: File -> Export
    Set your Kind to Jpeg
    Select your preferred Quality
    Check the Boxes at 'Titles and Descriptions' and Location Information
    Under FIlename select 'Use Title'
    Click on Export. In the Next Window choose a New Folder as your export destination and then Name that as you prefer
    Regards
    TD

  • How do you have more than 1 ipod in your family and only 1 computer to be able to each have a separate account?

    HOw do you have more than 1 ipod int he family and be able to have your own itunes on 1 computer?

    Did you read the support document at the other end of the link? What additional information do you desire?
    The Apple support document How to use multiple iPods with one computer (n.b. same link as above!) suggests a number of ways for managing the media content. I use method two (Sync with selected playlists) with a slight twist. Rather than regular playlists I set the grouping field to indicate which users should receive which tracks and create smart playlists based on the content of this field.
    e.g.
    "Alice's Tracks" is "Grouping contains Alice" + "Kind contains audio"
    "Bob's Videos" is "Grouping contains Bob" + "Kind does not contain audio"
    Tracks that both Alice & Bob want on their iPods have the grouping set to "Alice/Bob"
    etc.
    I currently manage our family's five iDevices using this system, each getting a different selection to suit their tastes and the capacity of their device. An advantage of using the grouping field is that it is stored in file tags (for non-wav audio files anyway) so that it is relatively easy to recreate the playlists should the iTunes library get trashed and need rebuilding. Also useful if you move files about manually as playlist membership is preserved when you delete & re-import the tracks.
    tt2

  • How do you have Google searches appear in new tab? This was previously not a problem, but it changed and I cannot return the setting. Any ideas?

    How do you have Google searches appear in new tab? This was previously not a problem, but it changed and I cannot return the setting. Any ideas?

    I recently purchased a second hand new macbook air, although it was second hand to me the previous owner had never actually turned it on.
    Something doesn't make sense here, though I'm not saying the previous owner is lying....
    Time to send your serial # to iTS and let them see what's happening here.
    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html

  • How do you lock individule cells in numbers on ipad

    how do you lock individule cells in numbers on ipad

    Wayne, are you sure its iOS numbers that can lock the table? If so, could you please show me how? Havent figured it out yet.
    Thanks
    Jason

  • How do you have a file automatically open in mail, like a Constant Contact email?

    How do you have a file automatically open in mail, like a Constant Contact email?
    Thanks,
    Lauren

    If there is a way to automatically open an attached file in a Mail item, it is not one that I would use, because I want to stay in control of my Mac!  Who is it from, whats in it and so on... To me bad idea but then the choice is yours.

  • How do you have JList display user defined element

    How do you have JList display the element you define???
    I tried:
    list.setSelectedIndex( 1 );
    list.ensureIndexIsVisible(1);
    because I want the element at index[1] in the list to be displayed when the GUI opens. It always defaults to element [0] (1st element).
    So if I have
    String[] colors = {blue, red, yellow};
    when the GUI opens, I want "red" to appear in the JList, but blue is always displayed...

    Sorry, that must've been cut off, here it is...
    What I want it to do is open and I want "green" to be the only element showing in the JList...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.Container;
    import javax.swing.JOptionPane;
    import java.lang.Object;
    import java.awt.event.*;
    import java.awt.Component;
    import javax.swing.JOptionPane;
    import java.awt.BorderLayout;
    //import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    //import javax.media.jai.JAI;
    //import javax.media.jai.PlanarImage;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JComponent;
    import javax.swing.SpringLayout;
    import javax.swing.border.BevelBorder;
    * Simple applications for demonstrating the use of FormUtility
    * to hide the details of creating a form layout with
    * GridBagLayout.
    * <P>
    * Philip Isenhour - 060628 - http://javatechniques.com/
    public class correctOfficerGUI extends JFrame
            private JPanel form;
            private final JFrame f;
            //public final int lineCount = 0;
            //EASTERN NY
            public static String nameInfoString   = new String();
            String facilities[] = {     "blue",     "green", "yellow"};
        public correctOfficerGUI()
            //JFrame
            f = new JFrame("Add Officer");
            //int x = f.DoModal();
            // Make a panel to hold the demo �form", then
            // add it to the top of the frame�s content pane
            //JPanel
            form = new JPanel();
            f.getContentPane().setLayout(new BorderLayout());
            f.getContentPane().add(form, BorderLayout.NORTH);
            // Set the form panel�s layout to GridBagLayout
            // and create a FormUtility to add things to it.
            form.setLayout(new GridBagLayout());
            JPanel spacerPanel = new JPanel();
            spacerPanel.setLayout(new BorderLayout());
            final JList list = new JList(facilities);
            int index = 2;
         list.setSelectedIndex( 1 );
            list.setVisibleRowCount(1);
         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
         //contentpane
            form.add(new JScrollPane(list));
            JButton addButton = new JButton("Add");
            form.add(addButton);
            //addButton.add(       
         addButton.addActionListener(
              new ActionListener()
              public void actionPerformed( ActionEvent actionEvent )//valueChanged(ListSelectionEvent e)
                        //f.DoModal();
                        System.out.println("********************************************");
                        JOptionPane.showMessageDialog(null, "The Officer has been Added.");
            // Add an little padding around the form
            form.setBorder(new EmptyBorder(2, 2, 2, 2));
            f.setSize(300, 300);//230);
            f.setVisible(true);
        public static void main(String[] args)
            correctOfficerGUI test = new correctOfficerGUI();
         test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
    }Message was edited by:
    poncho

  • How to reset your secret question, when you have forgot the answer. And how to change the email where the reset confirmation will be send towards?

    can anybody help with the question below?
    how to reset your secret question, when you have forgot the answer. And how to change the email where the reset confirmation will be send towards?

    You won't be able to change your rescue email address until you can answer your questions, if you don't have access to your current rescue account then you will need to contact Support in your country to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset you can then use steps 1 to 7 half-way down this page to update your rescue email address for potential future use : http://support.apple.com/kb/HT5312

  • How do you have couninous play with cover flow

    How do you have continous play with cover flow

    You don't. It plays from the track you select to the end of the album, optionally repeating.
    tt2

  • How do you record video with usb mic and have the audio from garageband be the sound when recording and not just your normal voice but garage band effects for youtube?

    How do you record video with usb mic and have the audio form garageband be apart of the video when recording, meaning the audio from garageband and echo  and not just your normal voice for youtube post?its not add the garageband audio its just normal voice from mic no  effects is going thru?

    Hi Life93,
    What you describe would be possible by recording your video, then removing the audio from it and adding audio from GarageBand once the video is in iMovie (I presume here that you are using iMovie for your video production. Other applications may need different methods.)
    See this thread on how to remove the audio from a clip in iMovie -
    Is there a way to separate audio from a video c...
    https://discussions.apple.com/thread/1779767
    To add audio from GarageBand use this article -
    iMovie '11: Add a sound clip to your project
    http://support.apple.com/kb/PH2255
    Thanks for using Apple Support Communities.
    Best,
    Brett L

Maybe you are looking for

  • Header file entry for Text Channel

    I have taken an ASCII Text Data file, read the file, and created a Header File, then saved the data into a binary file. This is my attempt to speed up the loading of the text file. One of the columns is a text column, containing a flag for the state

  • Adobe premiere has encountered an error

    Premiere CC bringt diese Fehlermeldung. Habe dann versucht mit einen neuen Benutzer, dann ging es, aber nur für einen Tag! Was kann ich noch machen?

  • Why setRolloverIcon cant function in JToolBar ** NEED HELP ** URGENT

    this is the sample coding * WHY when the user positions the mouse over button...the Images dint change import javax.swing.JToolBar; import javax.swing.JButton; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JTextArea; imp

  • Wireless DHCP

    I've just taken over the managment of a new wireless solution. They currently have only one WLAN and want to implement a second for guests only, so they only have access to the internet and no internal devices. The controller is a AIR-WLC52 running 4

  • Update Database with XML

    We update several thousand product prices in our MYSQL database daily using an XML feed. We can update the database using by looping over the XML and updating the database on an item by item basis but that seems awfully inefficient. Is there a better